google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Write a Program to Implement to Single Inheritance in Java

Write a Program to Implement to Single Inheritance in Java

0
Single inheritance enables a derived class to inherit properties and behavior from a single parent class. It allows a derived class to inherit the properties and behavior of a base class, thus enabling code reusability as well as adding new features to the existing code. This makes the code much more elegant and less repetitive.

Syntax

class A{
 //Do something
}
class B extends A{
 //Do something
}
class C extends A{
 //Do something
}

Single Inheritance Example Program

class SingleInheritance{
 static int num1=10;
 static int num2=5;
}

class MainInheritance extends SingleInheritance{
 public static void main(String[] args){
 int num3=2;
 int result=num1+num2+num3;
 System.out.println("Result of child class is "+result);
 }
}

Sample Output

Output is:
Result of child class is 17

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top