CORE JAVA QUESTIONS - Part II

Sunday, March 11, 2012

Can an anonymous class be declared as implementing an interface and extending a class?
          An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.

What is the range of the short type?
The range of the short type is -(2^15) to 2^15 - 1.

What is the range of the char type?
The range of the char type is 0 to 2^16 - 1.

CORE JAVA QUESTIONS

What is the difference between an Interface and an Abstract class?
          An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

What is the purpose of garbage collection in Java, and when is it used?
          The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.