Tuesday, July 14, 2009

Core Java Doubts?

1. what is the impact of private constructor?


2. what r static initializers?


3. can we assign parent objects to child objects?


4. what r singleton classes?


5. can applets be embedded in any graphical java application?


6. in use of applets having main() ?


7. how is the template concept of C++ implemented in Java?


8. can main() have only void as its return type?





plz answer them with the ques nos.

Core Java Doubts?
1. Instances of the class with only private constructors can only be created from within that class itself.





2. Static initializer is a piece of code enclosed in static { } that is executed when the class is loaded (referenced) for the first time.





3. No, you can't assign parent objects to child objects. Parent objects are not compatible with child objects and may not have all required methods/variables.





4. Singleton class is the class that only allows existense of one and only instance of itself.





5. Applets can be embedded into web browser and viewed in applet viewer - yes. Any graphical Java application - no.





6. Didn't get this question. Applets don't normally have main() method - they have init() method which performs similar function.





7. Semantics of templates in Java are almost the same as as in C++. Templates are classes that know how to deal with other classes, without knowing their specifics. Templates in Java are mostly intended to avoid clumsiness of typecasts.





8. Yes, main() can only be void if you want it to be program's entry point. If you make it not void, Java just won't recognize it as entry point function.
Reply:adding to the above answer:





1. See this for explanation


http://www.javapractices.com/topic/Topic...





6. You can have a main() method in an applet. It would imply that you plan to run your program an application as well.





7. It is implemented via "generics" introduced with Java 5


http://java.sun.com/j2se/1.5/pdf/generic...


No comments:

Post a Comment