public class Inheritance {
public static void main(String[] args) {
// TODO Auto-generated method stub
Second obj = new Second();
First obj1 = new First();
obj.setage(10);
obj1.setage(20);
System.out.println("The value is " +obj.i);
System.out.println("The value is " +obj1.i);
}
}
public class First {
int i;
String S;
void setage(int i){
this.i=i;
}
void setname (String S){
this.S=S;
}
int getage(){
return i;
}
String getname(){
return S;
}
}
class Second extends First{
int j;
void setrollno(int i){
j=i;
}
}
output:-
Test one
Test Two
No comments:
Post a Comment