elibraryportal Logo

Core Java OOPs Concepts Interview Question .

1) Difference between object oriented programming language and object based programming language?

→ Object based programming languages follow all the features of OOPs except Inheritance. Examples of object based programming languages are JavaScript, VBScript etc.

2) What is constructor

  • Constructor is just like a method that is used to initialize the state of an object. It is invoked at the time of object creation.
  • Constructor name must be same as its class name
  • Constructor must have no explicit return type

3) What is the default constructor ?

→ if there is no constructor in the class java compiler creates a default constructor. And Default constructor provides the default values to the objects.

→ Default Constructor" when it doesn't have any parameter. It is called .

4) What Does constructor return any value ?

→ yes, that is current instance .

5) Is constructor inherited ?

→ constructor is not inherited.

6) Can you use a constructor with final?

→ No, constructor can't be final.

7) What is static variable ?

→ static variable gets memory only once in class area at the time of class loading.

→ static variable is used to refer the common property of all objects.

8) What is static method?

→ static method can access static data member and can change the value of it.

→ A static method belongs to the class rather than object of a class.

9) Why main method is static?

→ If main method were not declared static than JVM has to create instance of main Class and since constructor can be overloaded and can have arguments there would not be any certain and consistent way for JVM to find main method in Java.Since the main method is static Java virtual Machine can call it without creating any instance of a class which contains the main method.

10) What is static block?

→ Static block initialize the static data member.

11) What is "this" keyword in java ?

this:- It is a keyword , that refers to the current object

→ Used to refer current class instance variable.

→ To current class constructor.

→ It can be passed an argument in the method call.

→ It can be passed argument in the constructor call.

→ Used to return the current class instance.

→ Used to invoke current class method

12) What is Inheritance ?

→ It represents the IS-A relationship, also known as parent-child relationship.

→ One object acquires all the properties and behaviors of parent object.

→ Inheritance allows a class to use the properties and methods of another class.

→ In Inheritance allowed, a class to inherit property of another class. When a Class extends another class it inherits all members including fields and methods. such as Parent - Child relationship.

More details

13) What is method overloading?

→ If class contains multiple method, same name but different parameter is know as Method Overloading

14) What is method overriding ?

→ Same method and same parameter know as Method Overriding .

15) What is Difference between method Overloading and method Overriding.

NO.Method OverloadingMethod Overriding
1)Method overloading occurs within the class.Method overriding occurs in two classes that have IS-A relationship between them.
2)same name but different parameter
Method Overloading means more than one method shares the same name in the class but having different parameters.
Same method and same parameter
3) This is a compile time polymorphism.This is a run time polymorphism.
4)It may or may not need inheritance in Method Overloading.Where It always requires inheritance in Method Overriding.
5)Method Overloading does not require more than one class for overloading.
    Class Add{
   int sum(int a, int b)
     return a + b;
  int sum(int a)
    return a + 10;
Where Method Overriding requires at least two classes for overriding.
Class A  // Super Class
  void display(int num)
     print num ;
//Class B inherits Class A
Class B //Sub Class
  void display(int num)
     print num ;

16) What is final variable, final method, and final class?

final variable : If you make any variable as final, you cannot change the value of final variable.

final method :A final method is a method that can't be overriden.

final class : A final class that can not be overriden or inherited..

17) What is blank final variable?

In java , A blank final variable that is not initalized at the time of declaration, is known as blank final variable.

18) Can we intialize blank final variable?

Yes! You can initialize a blank final variable in constructor or static block block.

19) Can you declare the main method as final in java ?

Yes. You can declare main method as final

But, In inheritance concept we cannot declare main method as final in parent class because create compile time error.

20) What is Polymorphism ?

Polymorphism is one of the OOPs concepts that allows us to perform a single action in different ways. the best example of Social media

There are Two types of Polymorphism that is.

  1. Compile time Polymorphism
  2. Runtime Polymorphism example
Next Topic