1. How do you create a read-only collection? (donated Mar 9, 2005)
The Collections class has six methods to help out here:
1. unmodifiableCollection(Collection c)
2. unmodifiableList(List list)
3. unmodifiableMap(Map m)
4. unmodifiableSet(Set s)
5. unmodifiableSortedMap(SortedMap m)
6. unmodifiableSortedSet(SortedSet s)
If you get an Iterator from one of these unmodifiable collections, when you call remove(), it will throw an UnsupportedOperationException.
2. Can a private method of a superclass be declared within a subclass?
Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.
3. Why Java does not support multiple inheritence ?
Java DOES support multiple inheritance via interface implementation.
4. What is the difference between final, finally and finalize?
o final - declare constant
o finally - handles exception
o finalize - helps in garbage collection
5. Where and how can you use a private constuctor.
Private constructor can be used if you do not want any other class to instanstiate the object , the instantiation is done from a static public method, this method is used when dealing with the factory method pattern when the designer wants only one controller (fatory method ) to create the object .
6. In System.out.println(),what is System,out and println,pls explain?
System is a predefined final class,out is a PrintStream object and println is a built-in overloaded method in the out object.
7. What is meant by "Abstract Interface"?
First, an interface is abstract. That means you cannot have any implementation in an interface. All the methods declared in an interface are abstract methods or signatures of the methods.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment