Summary of Object-Oriented Programming (OOP) Concepts in Java

Object-Oriented Programming (OOP) uses "objects" to model realworld objects. 

Object-Oriented Programming (OOP) consist of some important concepts namely Encapsulation, Polymorphism, Inheritance and Abstraction. These features are generally referred to as the OOPS concepts. 

If you are new to object oriented approach for software development, you can first read about object oriented approach in little more detail @ object-oriented-systems-development

An object in OOP has some state and behavior. In Java, the state is the set of values of an object's variables at any particular time and the behaviour of an object is implemented as methods.

Class can be considered as the blueprint or a template for an object and describes the properties and behavior of that object, but without any actual existence. An object is a particular instance of a class which has actual existence and there can be many objects (or instances) for a class.

Static variables and methods are not purely object oriented because they are not specific to instances (objects) but common to all instances. 



Encapsulation is the process of wrapping up of data (properties) and behavior (methods) of an object into a single unit; and the unit here is a Class (or interface). 

Encapsulate in plain English means to enclose or be enclosed in or as if in a capsule. In Java, everything is enclosed within a class or interface, unlike languages such as C and C++ where we can have global variables outside classes. 

Encapsulation enables data hiding, hiding irrelevant information from the users of a class and exposing only the relevant details required by the user. We can expose our operations hiding the details of what is needed to perform that operation. 



Inheritance describes the parent child relationship between two classes.

A class can get some of its characteristics from a parent class and then add more unique features of its own. For example, consider a Vehicle parent class and a child class Car. Vehicle class will have properties and functionalities common for all vehicles. Car will inherit those common properties from the Vehicle class and then add properties which are specific to a car.

In the above example, Vehicle parent class is known as base class or superclass. Car is known as derived class, Child class or subclass.

Java supports single-parent, multiple-children inheritance and multilevel inheritence (Grandparent-> Parent -> Child) for classes and interfces.

Java supports multiple inheritance (multiple parents, single child) only through interfaces. This is done to avoid some confusions and errors such as diamond problem of inheritance. 



The ability to change form is known as polymorphism. Java supports different kinds of polymorphism like oveloading and overriding.



The same method name (method overloading) or operator symbol (operator overloading) can be used in different contexts.

Java doesn't allow operator overloading except that "+" is overloaded for class String. The "+" operator can be used for addition as well as string concatenation.

Overloading may be also called compile time polymorphism. 


Overriding (or subtype polymorphism)

We can override an instance method of parent class in the child class.

When you refer to a child class object using a Parent reference (e.g.  Parent p = new Child()) and invoke a method, the overriden child class method will be invoked. Here, the actual method called will depend on the object at runtime, not the reference type. 

Overriding is not applicable for static methods or variables (static and non-static). In case of variables (static and non-static) and static methods, when you invoke a method using a reference type variable, the method or variable that belong to the reference type is invoked.

Overriding may be also called runtime polymorphism.



In plain English, abstract is a concept or idea not associated with any specific instance and does not have a concrete existence.

Abstraction in Object Oriented Programming refers to the ability to make a class abstract.

Abstraction captures only those details about an object that are relevant to the current perspective, so that the programmer can focus on a few concepts at a time.

Java provides interfaces and abstract classes for describing abstract types.

  • An interface is a contract or specification without any implementation. An interface can't have behavior or state.

  • An abstract class is a class that cannot be instantiated, but has all the properties of a class including constructors. Abstract classes can have state and can be used to provide a skeletal implementation. 


The Object class

All classes in Java are actually direct or indirect sub classes of the java.lang.Object class directly or indirectly. Hence methods of the Object class are inherited by all classes in Java. You will read more about the Object class later.


when we extend any super class then sub class inherits all the members of super class except private member,, but when we create object of sub class then it include all super class and sub class data including private member ??? am i r8?

Was it useful?

This is an area of confusion to many. 

Java specification says clearly that "A subclass does not inherit the private members of its parent class.".

In inheritance, a class can get some of its characteristics from a parent class. Inherited fields can be accessed just like its normal fields (using this keyword). Note that when you don't provide this, a this is automatically added. A private field is not inherited means that it cannot be accessed (using this keyword) from a subclass like other methods.

However there is also a rule that when you create an object, it should call its super constructor. When this super constructor is called, the super class object is created with all fields, however only inherited fields can be accessed.

Below example should clear your doubts:

public class Parent {

  Parent(int i, int j) {
    this.i = i;
    this.j = j;

  private int i;
  public int j;

  public static void main(String[] args) {
    Child c = new Child(5, 10);

  void printIJ() {
    System.out.println(i + " " + j);

class Child extends Parent {
  Child(int i, int j) {
    super(i, j);
    // this.i=25;
    this.j = 15;

I have commented out the line with this.i as that is not valid. i is a private field, hence not inherited and hence cannot be accessed using this keyword. However we can still access it using an accessible method indirectly as in this case. printIJ is accessible from subclass and printIJ can then access those private variables as printIJ  is a parent class method, which was inherited.

Another thing to understand is that private, protected and private are access modifiers and they control access to those variables. To understand better, refer to and

Was it useful?

i know when we create an objects like Usman usm = new Usman(); then usman class object is created and it's memory address or reference is assigned to usm reference variable. but some time i confuse that when we create and object then what we say it ? usman type object is created or usm object is created of type usman ?

actually when we read most of books then it will create some confusion,, like in every book there is some new thing,,, like complete reference , we can say usm an object and in realily it holds object reference ,, but in rose india site , we cannot say usm as object?? plzz explain what will be right ?

Was it useful?

simple and nice explanations :)

Was it useful?

Thanks for the overview.

Was it useful?

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)