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

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

Wiki User

10y ago

Inheritance allows to logically relate classes.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

I does not.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How does inheritance helps prevent errors in programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why you need to use inheritance?

Inheritance is an object oriented programming concept that helps us with the following benefits:You can reuse existing code instead of having to write them againredundancy of code is avoidedrework and maintenance is easy


what helps prevent errors in DNA replication?

DNA polymerase checks the DNA for errors.


Knowing the difference between the niprnet and siprnet helps prevent what?

It helps to prevent Spillage.


Advantages of computer programming?

The advantages of computer programming is that it pays well since programming is a creative task. Computer programming helps human beings solve problems on a regular basis.


What is the meaning of the word programming?

The definition of the word "Programming" is "the action or process of writing computer programs." Hope this helps.


Why do you have to focus on object oriented program?

Well, it certainly makes programming much, much easier. It is confusing at first, but it helps a lot, once you master it.Well, it certainly makes programming much, much easier. It is confusing at first, but it helps a lot, once you master it.Well, it certainly makes programming much, much easier. It is confusing at first, but it helps a lot, once you master it.Well, it certainly makes programming much, much easier. It is confusing at first, but it helps a lot, once you master it.


What is testing in computer programming?

In computer programming, testing is the process of evaluating software to identify any potential defects or errors. It typically involves running the program with different inputs to verify that it behaves as expected and meets the specified requirements. Testing helps ensure the quality and reliability of the software before it is released to end users.


Does blubber help to prevent water loss from the body?

Blubber, or subcutaneous fat, helps prevent heat loss from the body. Keratin in the epidermis helps prevent water loss from the body.


Do I need to be really good a math to figure out computer programming?

It helps to have a basic math education. Most programming does not require using math at all. The calculations a lot of the time built into the programming code and is done for you


What is the box called that helps show the possible outcome for dominant and recessive gene inheritance?

punnett square


What helps prevent dislocations?

plaster should be


What are the factors that helps prevent accident?

wala