Logo

dev-resources.site

for different kinds of informations.

Day14 Inheritance:

Published at
12/29/2024
Categories
payilagam
java
programming
chennai
Author
reegan
Author
6 person written this
reegan
open
Day14 Inheritance:

INHERITANCE:

 * Inheritance is implemented using the extends keyworrds.

 * Inheritance in java is a mechanism where one class child or subclass acquires the properties and behaviors fields and methods of another class parent or superclass.

 * subclass (child) - the class that inherits from another class

 * superclass (parent) - the class being inherited from To inherit from a class, use the extends keyword. # 
Enter fullscreen mode Exit fullscreen mode

Example program:

package reegan;
class Dad
Enter fullscreen mode Exit fullscreen mode

{
int money=2000;
}
class son extends dad
{

}
public class mainclass
{
public static void main(String []args)
{
son s1=new son();
System.out.println(s1.money);
}
}

Image description

Featured ones: