Java OOP

First we should know what is OOP?

OOP stands for objects oriented programming.It is a programming language paradigm which uses objects and classes as it’s core components.In Procedural programming we use procedures or methods for perform operations on data but object oriented programming is about creating objects that contain both data and methods.

What are the Advantages of OOP?

oop provides many advantages for programme. some of them are-

  • oop faster and easier to execute.
  • oop provides clear data structure for the programme.
  • oop provides code reusability for the programme.
  • also oop provides security and flexibility for the programmes.

What are the classes and objects in oop ?

classes and objects are the two main parts of oop.

Look at the following example to see the difference between class and objects:

according the above example ,Vehicle is the class and car,van bus are the onjects.

So, a class is a template for objects, and an object is an instance of a class.When the individual objects are created, they inherit all the variables and methods from the class.

why specially java?

java is an object oriented programming language.

Everything of java is associated with classes and objects, along with java’s methods and attributes.For an example think about a car.Car is an real world object.It has attributes like weight ,color,brandname etc. Also car has methods like drive , park, brake, reverse etc.

How to create a class in java?

To create a class in java we can use “class” keyword.following example shows how to create a class with a name Main in java.

A class with a name “Main”

How to create an object in Java?

In java programming language we create objects from classes.

I showed you how to create class in java form above example now we can use it for create an object.

What are the four pillars in java?

In java oop concepts we learn about four main core concepts .these are four pillars in java.These are:

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

These concepts are very helpful for software development and maintenance.

This is a image of oop system.

What is Inheritance?

When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability.

What is Polymorphism?

Polymorphism is many types. In Java two types of polymorphism

1.Compile time polymorphism

2.Runtime polymorphism

Compile-time polymorphism achieved through method overloading. Runtime polymorphism achieved through method overriding.

What is Abstraction?

Hiding internal details and showing functionality is known as abstraction. For example phone call, we don’t know the internal processing.In Java, we use abstract class and interface to achieve abstraction.

What is Encapsulation?

Binding code and data together into a single unit are known as encapsulation.A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.

We will discuss these four pillars in oop in java later.

see you again later!!.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store