Answer Posted / shivaprasad
Inheritance is a form of software re usability in which new
classes are created from existing classes by absorbing their
attributes and behavior using the key word 'extends'.
The class which absorbs the properties is called 'sub class'
and the class which is used is called 'super class'.
Ex:
class Room
{
void roomAttributes()
{
int roomlength;
int roomheight;
int roombreadth;
String roomname;
}
void roomBehavior()
{
System.out.println("Two windows");
System.out.println("One 6.2*3.5 door");
}
}
public class BedRoom
{
public static void main(String[] args)
{
Room roomobj=new Room();
roomAttributes();
roomBehavior();
int area= room.length*room.breadth*room.height;
}
}
In the above example the room is a super class from which
bedroom(subclass) is inheriting the properties and
attributes. This is simple inheritence.
Similarly, multi level inheritence is also possible.
Ex: class A extends B
class B extends C
class C extends D
But, java does not support multiple inheritance.
Ex: class A extends B, c
For better reference : Deitei & Deitel or Balaguruswamy
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is the latest java version?
What is an 8 bit word?
Explain the difference between intermediate and terminal operations in java8?
What is ‘is-a ‘ relationship in java?
Explain when we should make an instance variable private.
Why do we need singleton class?
Explain the features of java?
explain what is transient variable in java?
What is generic class?
worst case complexities of Quick sort and Merge sort.
What is oop in java?
What restrictions are placed on method overloading in java programming?
What is the use of beaninfo?
what are three ways in which a thread can enter the waiting state? : Java thread
Differece between class and generic class?