Oops
Oops
Data Hiding :-
- Our Internal data should not go outside directly i.e. outside person cannot Access our internal
data directly.
Pillars of Oops :-
01. Abstraction - User friendliness.
02. Encapsulation - Security
03. Inheritance – Reusability
04. Polymorphism – Flexibility
Inheritance :-
- Whatever parent has by default available to child, but Child has by default not available to
parent.
- On the child reference we can call both parent and child class methods but on the parent
- parent class reference can be used to hold child class object but by using that we can only
- child class reference can not be use to hold parent class object.
- Private method on parent class object can not be available in child class.
i] Single Level inheritance - Parent
Child
Child
GrandChild
package parentChildRelationship;
Parent p1 = new Child(); // we can hold Child object by using Parent reference.
p1.methodOne();
// Child c1 = new Parent(); // we can not hold Parent object by using Child reference.
}
public static void methodOne() {
System.out.println("Parent Method One");
}
}
package parentChildRelationship; Console :
|____________|
Child
- Having more than one parent at the same level is called as Multiple inheritance.
- Any class can extends only one class at a time ie. can not extends more than one class
class A {}
class B {}
interface A {}
interface B {}
- There is no specific keyword to implement HAS-A Relationship but mostly use 'new'
operator.
class Car {
Composition :-
- Then the relationship between container and contained object is called Composition.
Car
Aggregation :-
- Relation between Car and Music player is week Bonding ie. Aggregation.
Polymorphism :-
Same name with different forms.
package methodOverRiding;
package methodOverRiding;
@Override
public String property(int pro) {
Abstraction :-
- To Hide internal implementation and just highlight the set of Services is called Abstraction.
Example :- By using ATM User Interface Screen bank people highlighting the set of services
Advantages of Abstraction :-
- Enhancement will become very easy without affecting the end user as we can perform any
- abstract is keyword.
Abstract class :-
- If we used abstract keyword with class then that class is considered as Abstract class
- We can't create object of Abstract class but Abstract class has default constructor.
- Abstract class can have non Abstract method, hence it provides 0 to 100% Abstraction.
Abstract Method -
- When action is common but implementation are different then we used Abstract Method.
package abstractKeyWord;
}
@Override
public void myMethod() {
System.out.println("My Method Override");
}
}
02. Interface -
- From java 1.8 we can write static method in side the interface.
- From java 1.8 we can write default method in side the interface.
package interfaceDemo;
}
}
package interfaceDemo;
package interfaceDemo;
@Override
public void showStudentData() {
System.out.println("Show Student Data Method Get Called");
}
@Override
public void getStudentData() {
System.out.println("Get Student Data Method Get Called");
}
@Override
public void registerStudentData() {
System.out.println("Register Student Data Method Get Called");
}
}