What is Inheritance in Java part-3

Inheritance in Java

Inheritance is the technique by which one article picks up the properties of another thing. This is noteworthy in light of the way that it supports the possibility of different leveled plan. As referenced earlier,most data is made administer able by hierarchical(thatis,top-down)classifications. For example, a Golden Retriever is a bit of the request dog, which along these lines is a bit of the warm blooded creature class, which is under the greater class animal. Without 

the usage of dynamic frameworks, every thing would need to describe most of its traits explicitly.How ever,by use of inheritance, an article need simply portray those attributes that make it stand-out inside its gathering. It can get its general characteristics from its parent. As such, it is the inheritance segment that makes it practical for one thing to be a specific event of an inexorably wide case. We ought to explore this method. 

"Heritage in Java is an instrument where one article gets all of the properties and practices of a parent object. It is a huge bit of OOPs (Object Oriented programming system). The idea behind inheritance in Java is that you can make new classes that are based subsequent to existing classes." 

 Inheritance is the framework by which one article gets the properties of something else. This is essential in light of the manner in which that it bolsters the likelihood of various leveled assembling. As referenced earlier,most learning is made direct capable by hierarchical(thatis,top-down)classifications. For instance, a Golden Retriever is a touch of the arrangement hound, which along these lines is a touch of the warm blooded animal class, which is under the more noteworthy class creature. Without 

the use of initiative chains of importance, everything would need to depict a large portion of its properties explicitly.How ever,by utilization of legacy, an article need basically portray those characteristics that make it novel inside its get-together. It can get its general properties from its parent. In that capacity, it is the legacy fragment that makes it valuable for one article to be a particular occasion of a powerfully wide case. We should explore this system. 

" Inheritance in Java is an instrument wherein one thing confirms the majority of the properties and practices of a parent object. It is an essential piece of OOPs (Object Oriented programming structure). The thought behind legacy in Java is that you can make new classes that are based ensuing to existing classes." 
   
                     












 1.SINGLE  

class am{ 

void eat(){System.out.println("eating...");}

}

class Dog extends AM{

void bark(){System.out.println("barking...");}

}

class TestInheritance{

open static void main(String args[]){

Canine d=new Dog();

d.bark();

d.eat();

}}

2.Multilevel Inheritance 


class am{

void eat(){System.out.println("eating...");}

}

class Dog extends am{

void bark(){System.out.println("barking...");}

}

class BabyDog extends Dog{

void weep(){System.out.println("weeping...");}

}

class TestInheritance2{

open static void main(String args[]){

BabyDog d=new BabyDog();

d.weep();

d.bark();

d.eat();

}}

3.Hierarchical Inheritance 


young lady AM{

void eat(){System.out.println("eating...");}

}

class Dog extends AM{

void bark(){System.out.println("barking...");}

}

class Cat extends Animal{

void meow(){System.out.println("meowing...");}

}

class TestInheritance3{

open static void main(String args[]){

Feline c=new Cat();

c.meow();

c.eat();

/c.bark();//C.T.Error

}}

4.multiple legacy 


class AM{

void msg(){System.out.println("Hello");}

}

class BM{

void msg(){System.out.println("Welcome");}

}

class C extends A,B{//acknowledge whether it were

open static void main(String args[]){

C obj=new C();

obj.msg();//Now which msg() framework would be brought?

}

}


Previous
Next Post »