Easy java questions quiz?

NeedsHelpPlease

New member
I have a few basic java questions, see how much you actually know about java and try awnser them

1. What does Static Mean?
2. What exactly is an iterator?
3. What does // for (Collection l : ls){...}// do?
4. What do ++i and i++ mean and what is the difference?
5. What does new do?
6. Whats the difference between reference, object and primative?
7. How does polymorphism work?
8. What does public/private/protected do?
 
1. What does Static Mean?

The Static modifier indicates that there is one copy of the object that's shared by all instances that have access to it.

2. What exactly is an iterator?

An object that traverses the elements of a collection.

3. What does // for (Collection l : ls){...}// do?

'//' indicates that the text after it is a comment

4. What do ++i and i++ mean and what is the difference?

'++i' is pre-incrementing and other is post-incrementing. When you use pre-incrementing, i is incremented (value increased 1) first and then the expression is evaluated.

e.g.

int i = 2;
int sum = ++i + 3;

In this example, sum equals 6. When you use post-incrementing, i is incremented after the expression is evaluated.

e.g

int i = 2;
int sum = i++ + 3;

In this example, sum equals 5.

5. What does new do?

'new' indicates that an object is created.

6. Whats the difference between reference, object and primitive?

A reference is similar to a C pointer; it's an address pointing to an object in memory. An object is a set of variables and methods defined in a class that resides on memory. A primitive is a data type—boolean, byte, short, char, int, long, float, double—they represent number and logic values.

7. How does polymorphism work?

It's going to take practice to understand it. In short, it's calling the correct method on an object, when it's handled by a reference to it's parent class.

e.g.

class Parent { void speak(){} }
class Child { void speak(){} }
void foo() { Parent p = new Child(); p.speak(); }

Child.speak() is the method that is called. Like I said, it will take practice to learn that.

8. What does public/private/protected do?

The public modifier indicates that a class/member is visible to all classes, with the correct import statement, of course. A private member is only visible inside the class, and you can't declare a class private. A protected member/class is visible inside the class, throughout the package, and to any classes derived from the class.
 
Back
Top