Java Interview Questions Answers

Question - 131 : - What's the difference between an interface and an abstract class?

Answer - 131 : - An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

Question - 135 : - What is similarities/difference between an Abstract class and Interface?

Answer - 135 : - Differences are as follows:
Interfaces provide a form of multiple inheritance. A class can extend only one other class. Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class. Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast.
Similarities:
Neither Abstract classes or Interface can be instantiated.

Question - 136 : - Which containers use a border layout as their default layout?

Answer - 136 : - The Window, Frame and Dialog classes use a border layout as their default layout.

Question - 137 : - How many methods in the Serializable interface?

Answer - 137 : - There is no method in the Serializable interface. The Serializable interface acts as a marker, telling the object serialization tools that your class is serializable.

Question - 138 : - Can an object's finalize() method be invoked while it is reachable?

Answer - 138 : - An object's finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object's finalize() method may be invoked by other objects.

Question - 139 : - Can one create a method which gets a String and modifies it?

Answer - 139 : - No. In Java, Strings are constant or immutable; their values cannot be changed after they are created, but they can be shared. Once you change a string, you actually create a new object. For example:
String s = "abc"; //create a new String object representing "abc"
s = s.toUpperCase(); //create another object representing "ABC"

Question - 140 : - To what value is a variable of the String type automatically initialized?