So lets start of with a simple say basic java inheritance program. I hope the program would be self explanatory.
class Baseclass{ //this is a base class whose properties will be extended//
int i;
void show(){
System.out.println(i);
}
}
class Subclass extends Baseclass{ //subclass inherits the properties of baseclass//
int j;
void display() {
System.out.println(j);
}
}
public class Demo{
public static void main(String[] args) {
Subclass object = new Subclass(); // creating object using Subclass //
object.i = 10;
object.j = 20;
object.show(); //calling a baseclass method using subclass object//
object.display();
}
}
0 comments:
Post a Comment