Code:
// Program on hierarchical inheritance
class Course
{
String insName = "Coding Atharva";
}
class Java extends Course
{
String cname = "JSE";
double cfee = 2600;
}
class Php extends Course
{
String cname = "PHP";
double cfee = 5000;
}
class Test
{
public static void main( String[] args )
{
Java obj = new Java();
System.out.println("\n\n Java Details: ");
System.out.println(obj.insName);
System.out.println(obj.cname);
System.out.println(obj.cfee);
Php obj1 = new Php();
System.out.println("\n\n PHP Details: ");
System.out.println(obj1.insName);
System.out.println(obj1.cname);
System.out.println(obj1.cfee);
}
}
Output:
// Program on hierarchical inheritance
class Course
{
String insName = "Coding Atharva";
}
class Java extends Course
{
String cname = "JSE";
double cfee = 2600;
}
class Php extends Course
{
String cname = "PHP";
double cfee = 5000;
}
class Test
{
public static void main( String[] args )
{
Java obj = new Java();
System.out.println("\n\n Java Details: ");
System.out.println(obj.insName);
System.out.println(obj.cname);
System.out.println(obj.cfee);
Php obj1 = new Php();
System.out.println("\n\n PHP Details: ");
System.out.println(obj1.insName);
System.out.println(obj1.cname);
System.out.println(obj1.cfee);
}
}
Output: