Write a Java Program to demonstrate the use of subclass.

Program Code:
import java.lang.*;
class parent
{
int m;
void get_m(int m)
{
this.m=m;
}
void display_m()
{
System.out.println("This is from parent : m = " +m);
}
}
class child extends parent
{
int n;
void get_n(int n)
{
this.n=n;
}
void display_n()
{
System.out.println("This is from child : n = " +n);
}
}
class childdemo
{
public static void main(String arg[])
{

child c=new child();
c.get_m(10);
c.get_n(20);
c.display_m();
c.display_n();
}
}

Output:
This is from parent : m = 10
This is from child : n = 20
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: