1 Answer - Sort by: Date | Rating
In Java programming, inheritance provides user to create a class that uses the properties or qualities of previous defined class, but defined class still uses its own properties. In example of inheritance in Java, I give you the example of a flower program. Suppose that you have a flower class in which you create the qualities of a flower like color, smell, type etc .Now you want to create a class that describes the types of flowers and this class uses the types as rose, sunflower, Lilly etc.
In a normal or simple program, you might have to modify the existing code vastly. But now you want to avoid the difficulty of extended old class, you use the object-oriented approach and create a new class. The new class created by inheritance; this new class (type) inherits all the data and methods from the tested old class (flower).
In inheritance you can use public, private, and protected keywords for control the level of inheritance. You create a new class which is known as child or derived class from a parent or superclass by using extends keyword; with the name of a keyword extends use in child class because you usually extend the abilities of the parent class. For example you have already created Flower class and now you are creating a subclass FlowerTypes.
Import Flower;
Class FlowerTypes extends Flower
Private Int myType;
Public FlowerTypes (int value)
Super (value);
myType = value;
Public void SetType (int value)
myType = value;
Public int GetType ()
return myType;
In a normal or simple program, you might have to modify the existing code vastly. But now you want to avoid the difficulty of extended old class, you use the object-oriented approach and create a new class. The new class created by inheritance; this new class (type) inherits all the data and methods from the tested old class (flower).
In inheritance you can use public, private, and protected keywords for control the level of inheritance. You create a new class which is known as child or derived class from a parent or superclass by using extends keyword; with the name of a keyword extends use in child class because you usually extend the abilities of the parent class. For example you have already created Flower class and now you are creating a subclass FlowerTypes.
Import Flower;
Class FlowerTypes extends Flower
Private Int myType;
Public FlowerTypes (int value)
Super (value);
myType = value;
Public void SetType (int value)
myType = value;
Public int GetType ()
return myType;
0
0
- How To Create An Application By Using Java Program?
- How To Make An Application By Using Java Program?
- What How The Step For Make Library Management?
- In Which Process We Can Start Java?
- How To Download Java IDE?
- Define The Concept Of Java Byte Code?
- How To Run Remote Method Invocation In More Machine?
- How To Run Java Remote Method Invocation In More Machine?
- How To Make A Java Program That Will Ask The User To Input A Number And Display All The Even Number And The Sum Of All Even Numbers Based On The Inputted/ Given Numbers?
- Is A Static Variable An Instance?
- How To Compile And Run Java Package?
- What Does Literati-on Mean?
- What Is Abstract Class In Details?
- What Is Meant By Remote Method Invocation In Java?
- What Is Meant By Package In Java?
- What Is Meant By Servlet In Java?
- When Was Java Released?
- What Is Latest Technologies In Java?
- Write A Program Using Do…..while Loop To Calculate And Print The First M Fibonacci Numbers?
- What Is The Difference Between Reference &instance Variable?
- Why Java Is Slow?
- What Is The Drawback Of Ms Access?
- What Is Replaced In Place Of Pointers In Java?
- What Replaces Pointers In Java?
- How Many Types We Create Object In Java?
- How To Write Java Program To Calculate Student Grade Using Inheritance Concept?
- Give Me A Instance Example In Java Program. Can You Help?
- Can You Give The Sample Program In Java?
- Can You Give Me A Simple Java Program?
- How To Give Input In Java Program?
- How Can We Run Java Program By Command Prompt? Give Answer In Steps Please?
- What Is Inheritance In Java?
- Why Isn't Multiple Inheritance Used In Java?
- Is Multiple Inheritance Possible In Java Or Not?

New Comment - Comments are editable for 5 min.