Core java interview questions on non-access specifiers

1.Can we override a static method?
No,because belongs to the class area.

2.What is static variable?

The static keyword in java is used for memory management mainly. Belongs to the class.

If you declare any variable as static, it is known static variable.

The static variable can be used to  refer the common property of all objects (that is not unique for each object) e.g. company name of employees,college name of students etc.    
The static variable gets memory only once in class area at the time of class loading.    

3.What is static method?
If you apply static keyword with any method, it is known as 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.   
4.Why main method is static ?
It is necessary to put main method as static because before any object are created java interpreter will call the main is entry point class.

5.What is static block?
Static block is mostly used for changing the default values of static variables.This block gets executed when the class is loaded in the memory. A class can have multiple Static blocks, which will execute in the same sequence in which they have been written into the program.

Is used to initialize the static data member.

It is executed before main method at the time of class loading. 
6.What is abstract class?
A class that is declared with abstract keyword, is known as abstract class in java. It can have abstract and non-abstract methods (method with body).it is used to implement the concept of abstraction we cannot create object abstract class.

7.Can there be any abstract method without abstract class?
No, if there is any abstract method in a class, that class must be abstract.

8.Can you use abstract and final both with a method?
No,because we can,t override.

9.Is it possible to instantiate the abstract class?
No, abstract class can never be instantiated.

10.Can we override static method?
No,because there is no declaration and definitions.

13.What is final variable?
When final used before variable it refer the variable as constant.

14.What is final method?
Constant method.

15.What is final class?
Constant class.

16.What is blank final variable?
Blank final variable contains its default value.

17.Can we initialize blank final variable?
No,because main is static method.

18.Can you declare the main method as final?

19.Can you make a constructor final?
Static method automatically invoke before obj creation instance only call after obj creation.

20.What is difference between static method and instance method?
Static method invoke before obj creation.invokes only after obj creation.

Related Post