answersLogoWhite

0

What is inheritence in java?

Updated: 8/11/2023
User Avatar

Wiki User

11y ago

Best Answer

Inheritance is an object oriented feature supported by Java wherein the features of one Java class can be inherited/made available in another class. This creates a parent child relationship between these 2 classes. Class Inheritance in java mechanism is used to build new classes from existing classes. The inheritance relationship is transitive: if class x extends class y, then a class z, which extends class x, will also inherit from class y. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.

Example:

public class Parent {

private String name = "Rocky";

public String getName(){

return this.name;

}

}

public class Child extends Parent {

public static void main(String[] args){

System.out.println("Name in Parent is: " + getName());

}

}

Here the getName() method is available only in the parent class but is directly used in the child class because the method is public and is directly accessible to the child class since it has extended the parent class.

Benefits of Inheritance:

One of the key benefits of inheritance is to minimise the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organisation of code and smaller, simpler compilation units.

Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass

User Avatar

Wiki User

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

Wiki User

11y ago

using parent class properties in child class...

http://docs.oracle.com/javase/tutorial/figures/java/concepts-bikeHierarchy.gif

[go to the link for the picture]

as it is shown is picture, here bicycle is a parent class while others are child and all child classes have the same property of parent class but they have also there own properties

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Hierarchical inheritance in simple sentence "creating one or more child classes from the parent class".

Ex: class A

{

.............

..............

}

class B extends A

{

.......

.............

}

class c extends B

{

'............

..............

}

class D

{

public static void main (string args[])

{

.....

.....

}

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Inheritance is a concept in java that will achieve super class properties inside of base class

called inheritance means we inherits data from parents class to chiled class

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Inheritance is a property by which a class can extend other class. All the functions can be used by parent class.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is inheritence in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why JAVA cantt support multiple inheritence?

It's by design.


What are the alternatives to inheritence in java?

Java does not support multiple inheritance; a subclass cannot have more than one parent. Java compensates for this with interfaces. A class can implement multiple interfaces, but can only extend one class.


Difference object oriented language object based language?

object base: that are not use subtype or inheritence is called object base. object oriented: that use subtypes and inheritence is called object oriented e.g vb.net and java.


What is feture of java?

These are follows: 1-It is a platform independency. 2-Multithreding. 3-polymorphism. 4-encapsulation. 5-inheritence. 6-multitasking.


Is inheritence in java only based on super class and sub class?

Yes. Inheritance is achieved by using the super class and sub class concept


If your father-in-law leaves an inheritence to your husband are you intitled to some?

According to property laws, inheritence is considered separate property which is owned by the heir. A spouse is not entitled to inheritence.


What do you mean by inheritence?

Inheritence is somethingt that you are given. Like a gift in a way. ( Read Genesis 26 and 27)


What is Mendelian inheritence?

Linkage


What is protected member in inheritence?

aw3e1123


How is the inheritence controlled in an organism?

With allels.


Why does animals get hemophilia?

Genetic inheritence.


Why did gandhi have a big nose?

Inheritence