Java OOPS Concepts

We used to hear OOPS very often whenever we come across JAVA language. In this post we are going to have a look at the OOPS concepts of the Java. Some of the object oriented languages are: C#, C++, PHP, Java, Python etc.

Main concepts of OOPS are:
  • Object
  • Class
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation
1. Object: 
A Java object is a combination of data and procedures working on the available data. An object has a state and behavior. The state of an object is stored in fields (variables), while methods (functions) display the object's behavior. Objects are created from templates known as classes. In Java, an object is created using the keyword "new".

Syntax of creating an object:

MyClass obj = new MyClass();

In above example, 
  • MyClass is class name, 
  • 'obj' is the object name (object name can be anything) 
  • 'new' is keyword of java which instantiates the object (or in simple language it creates the object
  • 'MyClass()'is the constructor of 'MyClass'

2. Class: 
Before create objects in Java, you need to define a class. A class is a blueprint for the object. We can think of class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows etc. Based on these descriptions we build the house. House is the object.
Since, many houses can be made from the same description, we can create many objects from a class.
Syntax to define a class:
class MyClass {
   // variables
   // methods
}
A class in java can contain:
  • Fields
  • Methods
  • Constructors
  • Blocks
  • Nested class and interface





3. Inheritance: 
If an object acquires all the properties of the parent class, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism. For detailed summary see this post: What is Inheritance in Java?

4. Polymorphism: 
Polymorphism in Java is a concept by which we can perform a single action in different ways. We can perform polymorphism in java by method overloading and method overriding. 

5. Abstraction: Abstraction in Java is to hide the implementation details from the user and providing the functionality. It can be achieved by Abstract classes or Interfaces.

6. Encapsulation: Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. For detailed summary see this post: What is Encapsulation in Java?



Java Methods   << Previous     ||     Next >>   Java Inheritance




Click here to find complete Java Tutorials Series


Subscribe FB Group Techlistic on FB
Join Telegram channel at https://t.me/techlistic
Feel free to ask queries or share your thoughts in comments or email me.

Comments

Popular Posts

Top 10 Demo Websites to Practice Selenium Webdriver Online

Future of Selenium Automation Testing as a Career Option

How to learn Selenium Webdriver on your own online

Selenium WebDriver - Take Screenshot and Partial Screenshot Commands

Selenium Webdriver - Overview & Features