Set - 9

Question 11 :

Difference between Vector and ArrayList?

Answer :

Vector is synchronized whereas arraylist is not.


Question 12 :

Difference between Swing and AWT?

Answer :

AWT are heavy-weight components. Swings are light-weight components. Hence swing works faster than AWT.


Question 13 :

What is the difference between a constructor and a method?

Answer :

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.


Question 14 :

What is an Iterator?

Answer :

Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.


Question 15 :

State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers. ?

Answer :

public : Public class is visible in other packages, field is visible everywhere (class must be public too) private : Private variables or methods may be used only by an instance of the same class that declares the variable or method, A private feature may only be accessed by the class that owns the feature. protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature. This access is provided even to subclasses that reside in a different package from the class that owns the protected feature. default :What you get by default ie, without any access modifier (ie, public private or protected). It means that it is visible to all within a particular package.