OOPs Concepts in Java

There are four basic OOPs Concepts in Java

  1.  Abstraction
  2.  Encapsulation
  3.  Polymorphism
  4.  Inheritance

Definition of Class / Object

Class describes all the attributes of object, as well as the methods that implements the behavior of member object. That means this is a template or blue print.
In object-oriented programming , a class is a template definition of the method s and variable s in a particular kind of object . Thus, an object is a specific instance of a class; it contains real values instead of variables.

Object is an instance of a class, it contains real values instead of variables.

Person employee=new Person();

OOPs Concepts in Java

Abstraction

Abstraction is separating the functions and properties that logically can be separated to a separate entity.
Abstraction in Object Oriented Programming helps to hide the irrelevant details of an object.

Encapsulation

Encapsulation is an OOPS concept to create and define the permissions and restrictions of an object and its member variables and methods. A very simple example to explain the concept is to make the member variables of a class private and providing public getter and setter methods. Java provides four types of access level modifiers: public, protected, no modifier and private.

Polymorphism

Polymorphism is the occurrence of something in various forms. Java supports various forms of polymorphism like polymorphic reference variables, polymorphic method, polymorphic return types and polymorphic argument types.

Polymorphic reference variables can hold any of its subtype class reference.

class A extends C{}
class B extends C{}
C cType = new A();
cType = new B();

Polymorphic method can be overloading or overriding.

Polymorphic return types and polymorphic argument types:

public class Poly {
public static void main(String[] args) {
setNumber(new Integer(1));
System.out.println(getNumber());
}

public static Number getNumber() {
Integer i = new Integer(1);
return i;
}

public static void setNumber(Number n) {
}
}

Inheritance

In object-oriented programming (OOP), inheritance is a way to reuse code of existing objects.
A class can inherit attributes and behavior from pre-existing class called base classes, superclasses, or parent classes. The resulting class is known as derived classes, subclasses, or child classes

Thanks for reading our “OOPs Concepts in Java” article. If you liked it, then please share with your friends and colleagues. If you have any feedback or doubt then please leave us a comment.

By the way, I am also really happy to announce some very exciting news: to celebrate the imminent release of Spring 5 and Java 9,  we launched our simulators SALE CAMPAIGN. We halved the price of our simulators at www.springmockexams.com and www.javamockexams.com for limited time only. Take a look here bit.ly/SMEBP and here bit.ly/JMEBP

If you are interested in collaborating with us, you can join our partner program at bit.ly/SMEPART  and here bit.ly/JMEPART