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
Post A Comment:
0 comments: