Ok my dear friends I will give you a good example for inheritance today.See the below code..
Save it as details.java and run as a normal java program.
We use keyword extends to inherit details/values.
Try to understand it...
class student{
String name="Manuja";
int age=24;
}
class Csstudent extends student{
String town="Kurunagala";
}
public class details{
public static void main(String[] args) {
Csstudent stu=new Csstudent();
System.out.println(stu.name);
//In class Csstudent there is no variable as name and it extends it form student super class
System.out.println(stu.age);
//In class Csstudent there is no variable as age and it extends it form student super class
System.out.println(stu.town);
}
}
Run the codes as follows in cmd. And have the output
Save it as details.java and run as a normal java program.
We use keyword extends to inherit details/values.
Try to understand it...
class student{
String name="Manuja";
int age=24;
}
class Csstudent extends student{
String town="Kurunagala";
}
public class details{
public static void main(String[] args) {
Csstudent stu=new Csstudent();
System.out.println(stu.name);
//In class Csstudent there is no variable as name and it extends it form student super class
System.out.println(stu.age);
//In class Csstudent there is no variable as age and it extends it form student super class
System.out.println(stu.town);
}
}
Run the codes as follows in cmd. And have the output