OOPs Concepts

OOPS (Object Oriented Programming Structures)

What is Abstraction?

  • Abstraction is the concept of hiding irrelevant (not related to the task) details.In other words, make complex/typical system simple by hiding the unnecessary detail from the user and make it user-friendly.
  • The abstract class specifies what functionality is provided but not how that functionality is provided.
  • For example, one does not want to understand how the engine works. Similarly one does not have to understand the internal implementation of the software objects.
  • Abstraction provides a way to hide the less essential properties so as to reduce complexity and increase efficiency.
  • Abstraction Example: Engine and Driver.

What is Encapsulation?

  • Encapsulation is the technique of making the fields in a class private and providing access to the fields through public methods. Encapsulation is also called as data hiding.
  • The benefits of encapsulation:
  • The capability of changing\updating your code without disturbing the code of others
  • Encapsulation gives maintainability, flexibility, and extensibility to our code.
  • The fields of a class can be made read-only or write-only.
  • A class can have total control over of what is stored in its fields.
  • A class is able to change the data type, and users of the class never need to the changes of their code.

 

What is Polymorphism?

  • Polymorphism is an important Object Oriented concept and widely used in all Object Oriented Programming Language.
  • Polymorphism word comes from ancient Greek where poly means many.Polymorphism means many forms.
  • Polymorphism in Java means the same object behave differently in a different place.
  • For e.g Lady is one of the example polymorphism.Same Lady object will behave differently when she is sister, wife and mother.
  • Example:-
package in.java4all.polymorphism;
public class AccountClass {
public String accountopen(){
return "Account Opened";
}
}
class SavingAccountClass extends AccountClass{
public String accountopen(){
return "Saving Account Opened";
}
}
class CurrentAccountClass extends AccountClass{
public String accountopen(){
return "Current Account Opened";
}
}

   NOTE:-


  • There are two kinds of polymorphism
  • Compile time polymorphism (static binding or method overloading)
  • Runtime polymorphism (dynamic binding or method overriding)


What is Inheritance in Java?

  • Inheritance in Java is an Object oriented or OOPS concepts, which is same as real-world Inheritance behaviour,
  • Inheritance allows code reuse in Java. Along with Abstraction, Polymorphism and Encapsulation, Inheritance forms the basis of Object-oriented programming.
  • Inheritance is implemented using extends keyword in Java and When one Class extends another Class it inherits all public members including fields and methods.
  • Parent class called as Superclass and child class as Subclass in Java programming language.
  • The class which extends another class becomes Child of the class it extends(Parent Class) and inherit all its behaviour which is not private.
  • There are a lot of example of Inheritance in Object-oriented world e.g. Dog inherit properties of Animal, Car inherits properties of Vehicle etc.
  • In Java programming language, Child class inherit its Parent class's property and behaviour like the real world where child inherits the property of parent.
  • EXAMPLE:-
public  class Vehicle {}
public  class FourWheeler extends Vehicle {}
public  class Car extends FourWheeler{}
public  class BMW extends Car{}




  • Both are in Java are two OOPs(Object Oriented Programming Structure) concepts but they are completely different to each other.
  • Encapsulation:- It is a process of binding or we can say wrapping of the codes that operates on the data into a single entity. This keeps the data safe from outside users.
  • Abstraction is the concept of hiding irrelevant/unnecessary details.In other words, make the complex/typical system simple by hiding the unnecessary detail from the user and make it user-friendly.

Comments

Popular posts from this blog

JAVA ARCHITECTURE

Introduction Of JAVA