answersLogoWhite

0


Best Answer

Inheritance is a feature in Java wherein one class will inherit or use the features of another class.

Ex: public class A extends B {

…

}

Here class A is the child class and B the parent. The child inherits the features/methods of the parent and can use them.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Assume you have a class Dog like this:

public class Dog{

int legNumber;

public Dog(){

legNumber = 4;

}

public void onomatopoeia(){

System.out.println("roaf roaf !!");

}

}

And then you get a special case of a dog that not sound "roaf roaf !!"; A hound. Instead of do all the work again you can extend the Dog class like this.

public class Hound extends Dog{

public void onomatopoeia(){

System.out.println("boof boof !!");

}

}

And the new class Hound now have all properties and methods in Dog. The only you have to do now is redefine the onomatopoeia method.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is inheritance explain with an example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is an inheritance Explain different types of inheritance in c?

C is not an object oriented language and therefore has no native support for inheritance.


Can explain sudden changes in inheritance patterns?

mutations


Can you give Practical example for multilevel Inheritance?

Grandfather-father-child relationship is an example for multi level inheritance..


Explain different types of inheritance of object oriented programming?

== ==


How can you inheritance as a sentence?

Example sentence - His inheritance was small in comparison to the size of the estate.


Are Blood groups are a classic example of what inheritance in humans?

Blood groups are a classic example of multiple allelic inheritance


How did the work of Mendel help explain inheritance of traits?

because of punjabi


When a trait has more than two alleles how is the trait inherited?

When more than two alleles are involved in the inheritance of a trait, it is called polygenic inheritance. Many quantitative characters have polygenic inheritance. Inheritance of blood groups is an example of polygenic inheritance in human being.When more than two alleles are involved in the inheritance of a trait, it is called polygenic inheritance. Many quantitative characters have polygenic inheritance. Inheritance of blood groups is an example of polygenic inheritance in human being.


Which is not an example of cytoplasmic inheritance?

sterile pollen


What is the inheritance of marfan syndrome is an example of?

Pleiotropy.


The inheritance of Marfan syndrome is an example of what?

Pleiotropy.


What is the likely mechanism of inheritance for a character with a large range of phenotypes Explain?

mech and cromosomes