Core Java Interview Questions with Answers - Part III
21)What is static method?
A static method belongs to the class rather than object of a class.
A static method can be invoked without the need for creating an instance of a class.
static method can access static data member and can change the value of it.
22)why main method is static?
because object is not required to call static method if It were non-static method,jvm creats object first then call main() method that will lead to the problem of extra memory allocation.
23)What is static block?
Is used to initialize the static data member.
It is excuted before main method at the time of classloading.
24)Can we execute a program without main() method?
Ans)Yes,one of the way is, by static block.more details...
25)What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".
26)What is this in java?
It is a keyword that that refers to the current object.
27)What is Inheritance?
Inheritance is a mechanism in which one object acquires all the properties and behaviour of another object of another class. It represents IS-A relationship. It is used for Code Resusability and Method Overriding.
28)Which class is the superclass for every class.
Object class.
29) Why multiple inheritance is not supported in java?
To reduce the complexity and simplify the language, multiple inheritance is not supported in java in case of class.
30)What is composition?
Holding the reference of the other class within some other class is known as composition.
Search Terms:
java interview questions and answers for experienced
java interview questions and answers for freshers
java interview questions and answers for 3 years experience
java interview questions and answers pdf
java interview questions and answers pdf download
core java interview questions and answers