answersLogoWhite

0


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

โˆ™ 2009-05-16 12:26:14
This answer is:
User Avatar
Study guides

What is a programming language

What does DOS stand for

What is a software that is distributed for free

What is application software

โžก๏ธ
See all cards
3.8
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
20 Reviews

Add your answer:

Earn +20 pts
Q: The importance of inheritance in object oriented programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the features of object oriented programming?

The features of object oriented programming are Abstraction, Encapsulation, Polymorphism & Inheritance


How do you create multiple inheritance in c?

You don't. Inheritance is a feature of object oriented programming languages. C is not object oriented.


Explain different types of inheritance of object oriented programming?

== ==


What are the defining traits of an object oriented language?

Object oriented programming languages must support the four fundamentals of object-oriented programming: encapsulation, abstraction, inheritance and polymorphism.


What is Object Oriented Programming Approach?

An object oriented programming approach is one in which we use the various object oriented concepts like inheritance, polymorphism, encapsulation, abstraction etc.


Why java is called object oriented programming?

Java is called an object oriented programming language because it implements many of the object oriented programming concepts like abstraction, encapsulation, inheritance etc.


What are the characteristic of Object Oriented programming?

Object oriented programming contains three characterestics they are 1. Encapsulation 2. Polymorphism 3. Inheritance


What are the three characteristics of object-oriented programming?

Encapsulation, Inheritance, and Polymorphism


3 pillars of object oriented programming?

Encapsulation, Polymorphism, and Inheritance.


What are the characteristics of object-oriented programming?

Encapsulation, inheritance, polymorphism and abstraction.


Why is inheritance a key feature of object oriented programming?

Inheritance is a key feature of object oriented programming because:It promotes code reuseIt avoids code redundancyJava allows us to use Inheritance extensively in our programs.


What is the distinct difference between object oriented concept and object oriented programming?

Object oriented concepts are a generalisation of the object oriented principals (encapsulation, inheritance, polymorphism and abstraction) without specifying a particular implementation of those principals. Object oriented programming is the application of those principals through an object oriented programming language.

People also asked