answersLogoWhite

0

Why you prefer to having parent class in java?

Updated: 8/17/2019
User Avatar

Wiki User

14y ago

Best Answer

Having a parent class in Java is not mandatory. It is a good approach to extend from a parent class that has much of the functionality that the current class needs already coded. This helps us re-use functionality/code and avoid redundant/duplicate code.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you prefer to having parent class in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the things not inherited from parent class in Java?

Private members are not inherited from the parent class.


What is the Object class parent?

Object is the topmost class in the Java Class hierarchy. There is no Class above Object. All classes in Java are implicitly derived from Object.


What is parent class in java?

Object Class is the parent class of all classes in java.Every class in the Java system is a descendant (direct or indirect) of the Object class.


What is immediate super class of runtime exception?

If you mean Java's RuntimeException class, its parent class is java.lang.Exception


What type of file is created by Java?

Java created a file called class, and is identified by having the .class at the end. This file includes a Java bytecode, which then can be used on the Java Virtual Machine.


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.


What modifier do you use to prevent that class from having any subclasses?

In Java, you use the final modifier to prevent a class from having any subclasses.


Extension file for Java?

Java source files have the .java extension, compiled Java class files have the .class extension.


What is inheirtance in java?

It is basically the same as inheritance in other languages. A derived class can inherit from a parent class, meaning that the derived class will have the characteristics (variables, and procedures - called fields, and methods, in this case) of the parent class. It may also have additional characteristics, defined directly in the derived class.


Why use function overriding in Java?

You use function overriding in Java when you inherit a bunch of features from a class and for a few particular cases alone, you do not wish to use the functionality of the parent class and wish to implement a custom feature in your class. In such cases, you create a method in your class with the same name and signature as in your parent class, thereby overloading it. this way only your current class will be used by the JVM unless specifically invoked by using the super keyword.


In java why method defined in super class need not to defined in subclass?

In Java, or in any object oriented language such as C++, a method defined in super (parent) class does not need to be defined in a subclass, because that is the primary purpose of inheritance. Object oriented programming allows you to define and declare a class that implements the behavior for an object. Inheritance allows you to refine, or subclass, that class by "reusing" all of the functionality of the parent class into the sub class, adding additional definition and declaration for the sub class. If the subclass needs to change a parent class method, it can overload that method. This is called abstraction.


What is the use of reusability in inheritance?

Inheritance in Java refers to the feature wherein the code/functionality of one class can be used in another class that extends this class. Example: public class Parent { ... .. } public class Child extends Parent { ... .. . } Here the class Child extends the class Parent and hence the methods of Parent are available for Child to use. This way we are re-using the code in the parent class in the child class instead of re-writing the whole thing again.