Inheritance, Polymorphism, Abstraction,Encapsulation
Object means a real word entity such as Name, Car, table etc.
Object-Oriented Programming is a method to design a program using classes and objects.
It simplifies the software development and maintenance by using below concepts:
Object
An object is a software bundle of related state and behavior.
Objects are made up of attributes and methods.
Attributes are the characteristics that define an object; the values contained in attributes differentiate objects of the same class from one another.
It models the state and behavior of a real-world object.
* Every class, except
* An object "knows" what class it belongs to, and can use class data and class methods, but a class does not "know" about its objects.
* It is represented using keyword 'Class'
Example :
Class Human{
String name, gender;
Float weight, age;
void speak(String message){ System.out.println(message);}
}
Class Human {
String name, gender;
Float weight, age;
void speak(String message){ System.out.println(message);}
}
Class Lady extends Human{
String bodyType,stages;
}
Class Men extends Human{
String bodyType,stages;
}
Here the parent class is 'Human' and the child classes are 'Lady' and 'Men'
* 'extends' keyword is used to represent Inheritance.
* Multiple class inheritance is not allowed in java
* Object is the super parent class i.e. it is at the top of class hierarchy
Polymorphism
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
Example:
class Alphabet{}
class X extends Alphabet{}
Alphabet a=new X();
* There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism
"Runtime polymorphism" or "Dynamic Method Dispatch" is a process in which a call to an overridden method is resolved at runtime rather than compile-time.
Method Overriding is the good example of Runtime Polymorphism.
"Compile time polymorphism" : The call to the overloaded method is decided at the compile time because all the methods are bind at compile time.
Method overloading is the good example for this.
In java, we use abstract class and interface to achieve abstraction.
An interface or abstract class is something which is not complete. To use interface or abstract class we need to extend and implement abstract method with concrete behavior.
Object means a real word entity such as Name, Car, table etc.
Object-Oriented Programming is a method to design a program using classes and objects.
It simplifies the software development and maintenance by using below concepts:
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Object
An object is a software bundle of related state and behavior.
Objects are made up of attributes and methods.
Attributes are the characteristics that define an object; the values contained in attributes differentiate objects of the same class from one another.
Class
"Collection of objects" is called class. It is a logical entity.It models the state and behavior of a real-world object.
* Every class, except
Object, has one and only one immediate
superclass* An object "knows" what class it belongs to, and can use class data and class methods, but a class does not "know" about its objects.
* It is represented using keyword 'Class'
Example :
Class Human{
String name, gender;
Float weight, age;
void speak(String message){ System.out.println(message);}
}
Inheritance
Inheritance provides a powerful and natural mechanism for organizing the code.
In this the child object inherits all the properties and behavior of the parent object.
Example:Class Human {
String name, gender;
Float weight, age;
void speak(String message){ System.out.println(message);}
}
Class Lady extends Human{
String bodyType,stages;
}
Class Men extends Human{
String bodyType,stages;
}
Here the parent class is 'Human' and the child classes are 'Lady' and 'Men'
* 'extends' keyword is used to represent Inheritance.
* Multiple class inheritance is not allowed in java
* Object is the super parent class i.e. it is at the top of class hierarchy
Polymorphism
Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.
Example:
class Alphabet{}
class X extends Alphabet{}
Alphabet a=new X();
* There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism
"Runtime polymorphism" or "Dynamic Method Dispatch" is a process in which a call to an overridden method is resolved at runtime rather than compile-time.
Method Overriding is the good example of Runtime Polymorphism.
"Compile time polymorphism" : The call to the overloaded method is decided at the compile time because all the methods are bind at compile time.
Method overloading is the good example for this.
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.
An interface or abstract class is something which is not complete. To use interface or abstract class we need to extend and implement abstract method with concrete behavior.
Comments
Post a Comment