सीधे मुख्य सामग्री पर जाएं

#49 What is Abstraction in Java | Real Life Example of Abstraction | Abstraction क्या है ?

package com.sudhirtheindian2.java123;

abstract class Animal1{
void leg(){
System.out.println("all animal have 4 legs");
}
void sleep(){
System.out.println("all the animal sleep");
}


abstract void eat();
abstract void sound();


}

class Dog1 extends Animal1{
@Override
void eat() {
System.out.println("eating meet");
}

@Override
void sound() {
System.out.println("bhow bhow.......");
}
}

class Cow1 extends Animal1{
@Override
void sound(){
System.out.println("ooooo...");
}
void eat(){
System.out.println("eating grass");
}

}
public class abstractClass {
public static void main(String[] args) {




// What is abstraction in java ?

// abstraction is nothing but hiding the essential information
// and show the only set of service

//

// example ----

// bank show only
// 1 deposit
// 2 withdrwal
// 3 checkbalance

// but code of deposit , withdrawl & checkbalance will not show
// becuase they are essential information

// In Java we can achieve abstraction two ways

// 1 abstract class 0-100 %
// 2 interface 100% client requirement and work according to client
//

// abstractClass Rule---

// 1 if a class contain at least one abstract method
// called abstract class

// 2 we can not create object for abstract class

// 3 it contains both abstract & non abstract method

// 4 action common or same but implementation is different


// if one method of class is abstract then all the
//// class will be abstract






Dog1 d = new Dog1();
d.eat();
d.sound();
d.leg();
d.sleep();

Cow1 c = new Cow1();
c.eat();
c.leg();
c.sound();
c.sleep();
}
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट