OBJECT-ORIENTED:
- To solve real-world problems using the concept of encapsulation, Data Hiding, inheritance polymorphism etc.
- The idea is to contain data and function as a single unit. Such a unit is called an object
- OOPS program and contains a number of objects. the data of an object can be accessed by the function associated with the object.
- OOP contains Six different classification:
- Class
- Object
- Inheritance
- polymorphism
- Abstraction
- Encapsulation
oops concept in java |
CLASS
A class is a container which stores data and functions. It is common to all the objects of its types. class is userdefined data type.
It is a blueprint for creating objects. To create a class, use the keyword class.
Syntax:
public class main
{
int x=5;
}
OBJECTS
It is instance of a class. You can create multiple objects with same behaviour, instead of repeating code. A class can have multiple objects.
Syntax:
public class main
{
int x=5;
public static void main(string[] arg)
{
main myobj= new Main();
System.out.println(myobj.x);
}
{
int x=5;
public static void main(string[] arg)
{
main myobj= new Main();
System.out.println(myobj.x);
}
}
INHERITANCE
It is the process of creating a new class from existing class. Base class is parent class and child class is sub class. The basic advantages of inheritance are reusability of code, saves timing. The are different
Types of inheritance they are:
• Single inheritance
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
POLYMORPHISM
polymorphism is defined as " one name many forms". There is no operator overloading in java ,java contains only function overloading.
TYPES OF POLYMORPHISM:
- Compile time polymorphism
- Run-time polymorphism
ABSTRACTION
Data abstraction it is an act of hiding implementational details from the outside world.
ENCAPSULATION
Wrapping up of data and functions in a single functional unit is called encapsulation.