Wednesday, 5 August 2015

Java OOP interview questions

  1. What is encapsulation?

    Encapsulation means keeping together the implementation (code) and the data it manipulates (variables). In Java a class contains the member variables (instance variables) and the code in methods. In a properly encapsulated Java class method defines how member variables can be used.
    Read more about encapsulation here.


  2. What is abstraction?

    Abstraction means hiding the complexity and only showing the essential features of the object. So in a way, Abstraction means abstracting/hiding the real working and we, as a user, knowing only how to use it.

    Real world example would be a vehicle which we drive with out caring or knowing what all is going underneath.

    Read more about abstraction here.


  3. Difference between abstraction and encapsulation?

    Abstraction is more about hiding the implementation details. In Java abstraction is achieved through abstract classes and interfaces.

    Encapsulation is about wrapping the implementation (code) and the data it manipulates (variables) with in a same class. A Java class, where all instance variables are private and only the methods with in the class can manipulate those variables, is an example of encapsulated class.
    Read more about difference between Encapsulation and Abstraction in Java here.


  4. What is Polymorphism?

    Polymorphism, a Greek word, where poly means many and morph means change, thus it refers to the ability of an object taking many forms. The concept of polymorphism is often expressed as "One interface, multiple methods".
    Where one general class may have the generic method and the derived classes (classes which extend the general class) may add their own specific method with implementation. At the time of execution "One interface" i.e. the general class will take "many forms" i.e. references of the derived classes.
    Read more about polymorphism here.


  5. What is inheritance?

    Inheritance is a mechanism, by which one class acquires, all the properties and behaviors of another class. The class whose members are inherited is called the Super class (or base class), and the class that inherits those members is called the Sub class (or derived class).
    The relationship between the Super and inherited subclasses is known as IS-A relationship.
    Read more about inheritance here.


  6. What Is a Class?

    In object-oriented terms class provides a blue print for the individual objects created from that class. Once a class is defined it can be used to create objects of that type.
    Read more about class here.


  7. What Is an Object?

    In object-oriented terms object is an instance of the class, which gets its state and related behavior from the class. When a new class is created essentially a new data type is created. This type can be used to declare objects of that type.
    An object stores its state in fields and exposes its behavior through methods.
    Read more about object here.


  8. What is method overloading?

    When two or more methods with in the same class or with in the parent-child relationship classes have the same name, but the parameters are different in types or number the methods are said to be overloaded. This process of overloaded methods is known as method overloading.
    Read more about method overloading here.


  9. What is method overriding?

    In a parent-child relation between classes, if a method in subclass has the same signature as the parent class method then the method is said to be overridden by the subclass and this process is called method overriding.
    Read more about method overriding here.


Related Topics

  1. Core Java basics interview questions
  2. Java String interview questions
  3. Java Exception Handling interview questions
  4. Java Collections interview questions
  5. Java Multi-threading interview questions
  6. Java Concurrency interview questions

No comments:

Post a Comment