Oops concepts in java

Object

Object is real world entity . with the help of object we can access member variables and member functions of class. Object is also used to allocate the memory for class.

Class

1.It is a collection of data members and member functions.
2.Data members are the variable used inside class.
3.Member functions are the function used to perform a task.
4.It is also called Userdefined data type.

Syntax of class


Data Abstraction

1.Abstraction means Data hiding ,in other word we can say that in this type of programming essential data is shown to the user or outside class and unessential data is hidden.
2. Hiding internal details and showing functionality is known as abstraction

3.Members defined with a public access specifier are accessible throughout the program.
4.Members defined with a private access specifier are not accessible throughout the program means private element of a class can be accessed only inside in its own class.

5. Abstraction can be done in 2 ways 

    1. Abstract class 

    2. Interface


Inheritance

1.The process of getting property of one class into another class is called Inheritance.


2.In other word we can say that the process of deriving a new class from an old class is called inheritance in which the new class is called derived or child or sub class and old class is called Base or Parent or Super class.


3.When a class inherits the property of a class it means it can access all the data member and member function of that class except private element.
3.In this type of programming mainly two types of classes are used.

  • Parent/Super/Base class
  • Child/Sub/Derived class

Parent/Super/Base class
The class which is inherited by another class is called Parent or Super or Base class.
Child/Sub/Derived class
The class which inherits the property of another class is called Child or Sub or Derived class.

How to inherit one class into another

Derived class extends Base class
Example
class Subtraction extends Addition
Here Subtraction is a Derived class and Addition is a Base class and extends is a keyword which is used to inherit one class into another.

Types of Inheritance

There are five types of inheritance in Java.

  • Single Inheritance
  • Multiple Inheritance
  • Multilevel Inheritance
  • Hierarchical Inheritance
  • Hybrid Inheritance

Polymorphism

1.It means one name many forms so we can say that in this type of programming same function is used to perform different kind of operation.
2.It is an important part of object oriented programming language.

Types of Polymorphism

  • Compile time Polymorphism
  • Runtime Polymorphism

Function overloading

1.The function with same name and different parameter is called function overloading.

Function Overriding

1.Function with same name and same parameter is called function overriding.
2.It is not possible to make two function with same name and same parameter in a single class therefor to implement function overriding derived class is used.

Encapsulation

wrapping up of data into single unit is called Encapsulation. data is member variables and member functions of a class.

 In Encapsulation member variables are private and to access this private members we need to use setters and getter functions.


Post a Comment

0 Comments