Common OOPS Concepts Every Java Developer Should Know

OOPS in JAVA 

As the name suggests, Object-Oriented Programming or OOPs refers to languages that uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc in programming.

Object oriented principles:

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Class 
  • Object 
  • Method

Abstraction: --- providing essential property and operation of an object by hiding internal things is called as abstraction.

Exp:- -- abstracting the monitor is nothing but providing some properties like color, height, width ,company, manufacturing date, cost etc, and some operation like switch ON ,switch OFF, increase brightness, decrease brightness etc. by hiding internal functionality of the monitor.  

 

Encapsulation: ----- placing all the properties and operation of an object at one place is called as encapsulation. The place is called as a class and properties are called as variable and operation are called as method/behavior.

In programming language: -------- writing a java class by placing variables and method inside that is called encapsulation

 

Polymorphism: ---- one form behaving differently in different situation is called as polymorphism.

Exp: -----one button in CPU will do two task called as switch ON and switch OFF.

 

Inheritance: ------ getting existing property and operation of an existing class to a new class is called as inheritance. The existing class is called as parent class/ base class and the new class is called as sub class/ child class/derived class.

In java: ------- the process of using the super class (parent class) functionality in subclass (child class) is called as inheritance.

class A{
  int a,b;
  void show(){
  System.out.println(a);
  System.out.println(b);
 }
}

Creating object:

Student s =new Student();
 A obj=new A();


When the above line is executed then the following things will happen:

A obj: ---------Memory will be allocated for the reference variable obj of type class A and default null have assigned . 

   obj        

NULL

8 byte

 

New operator: ---- this is used to allocate the memory for instance variable of the class.

In the above class A there are two instance variables called a and b , so in this  new operator allocate the memory for two variables a  and b .

A() :---- if constructor is available then it will be called to initialize the object or initialize the instance variable.

=  :---------- object address will assign to reference variable object

 

In this example obj  is reference variable of type A and it can store address of object of type A only.

Variable and methods of the class are called as member of the class.

Reference variable.member_name;

Exp:---    s.show();         method

                s.sid  ;               variable

Conclusion;

In this article we have covered all oops Topics and if you required coding for the same visit our GitHub portal Code Available Here.   

Chandra Sekhar

A Blogger and Author! This post was written and edited by me, a technologist. I started this site to share my inspirations, work, and free materials, which I hope others may find useful as well. Man with a creative streak who enjoys experimenting with various web design strategies.

Previous Post Next Post

Microservice Communication in a Distributed System