Computer Programming
Java Programming

The importance of inheritance in object oriented programming?

175176177

Top Answer
User Avatar
Wiki User
Answered
2009-05-16 12:26:14
2009-05-16 12:26:14

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

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0

Related Questions


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

The 3 essential concepts of Object Oriented Programming are:InheritanceEncapsulation &Polymorphism

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

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

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

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

No, Java is a object oriented programming not a pure object oriented programming Bcoz java does not support multiple inheritance.java is object oriented programming bcoz its implement the basic object oriented concepts like inheritace,polimophism, abstraction etc except multiple inheritance.For any query or suggestion plz mail me.deepeshsinghsati@gmail.com

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

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.

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.

Encapsulation, Polymorphism, and Inheritance.

Some of the major features of object oriented programming are:InheritancePolymorphismEncapsulationData hidingAbstractionetc.

Encapsulation, Inheritance, and Polymorphism

Inheritance, Abstraction, Polymorphism & Encapsulation.

The four pillars of Object Oriented Programming are:EncapsulationInheritancePolymorphismAbstrractionThese programs are meant to just talk about the object. They do not allow for any abstracts to be present.

Because it implements object oriented programming concepts like inheritance, polymorphism, encapsulation, abstraction, polymorphism etc etc.

JAVA is an Object Based Programming Language. it doesn't provide multiple inheritance and operator overloading. while Object Oriented Lanuages provides both.

Encapsulation, data hiding, inheritance and polymorphism.

Inheritance Encapsulation Polymorphism Abstraction

Encapsulation, inheritance, polymorphism and abstraction.

Encapsulation is one of the four pillars of object-oriented programming. The other three are inheritance, polymorphism and abstraction.

Java is called Object Oriented Programming Language because in Java, you can implement all the Object Oriented methodologies (inheritance, multi-inheritance, polymorphism, encapsulation) and Programing paradigm in Java is also Object Oriented.

Java is called an Object Oriented Programming Language because many of the object oriented programming concepts are implemented in Java. Some concepts are: 1. Class 2. Object 3. Inheritance 4. Encapsulation 5. Polymorphism 6. Abstraction etc.

You do not need object oriented programming. Anything that can be programmed in an object oriented programming language can be programmed in C.


Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.