Thursday, June 17, 2010

Java Interview Questions 2

<< Previous                                                                                    Next  >>

Java Interview Question 5:
What is an abstract class?

Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. A class that is abstract may not be instantiated. Its sole purpose is to be extended (subclassed). When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

Java Interview Question 6:
What is the final keyword denotes?

A final keyword can be used for class, method and variables. The keyword final denotes that it is the final implementation for that class or method or variables.

Final class: A class that is declared final cannot be a superclass. That is, no other class can extend (inherit from) a final class. In other words, Java classes declared as final cannot be extended/subclassed. All methods in a final class are implicitly final. Many of the Java standard library classes are final, for example java.lang.System and java.lang.String

Final method: If declaring an entire class final is too heavy-handed for your needs, you can declare some or all the class’s methods final instead. A final method indicate that the method cannot be overridden by subclasses. A method is marked as final if it has an implementation that should not be changed.

Final variable: A final variable can only be assigned once. The value of a final variable cannot change after it has been initialized.. A variable that is declared as final and not initialized is called a blank final variable.

Java Interview Question 7:
What is an exception?

The term "exception" means "exceptional condition" which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.


<< Previous                                                                              Next  >>


No comments: