Hierarchical inheritance is one of the types of inheritance where multiple child classes inherit the methods and properties of the same parent class. Hierarchical inheritance not only reduces the code length but also increases the code modularity.

program :
super calss:
class car{
String carname;
int carnumber;
/public car(String cname, int cnum){ carname=cnum; carnumber=cnum; }/
void driving(){
System.out.println(“driving”);
}
}
subclass1:
class maruticar extends car{
string mname;
void travelling(){
System.out.println(“travelling”);
}
}
subclass2:
class tatacar extends car{
String modelname;
void outing(){
System.out.println(“outing”);
}
public static void main(String args[])
{
tatacar z=new tatacar();
z.driving();
z.travelling();
z.outing();
}
}
output:

I have this error in output. incase of I avoid z.travelling the outing is running without any error.
for example:
class tatacar extends car{
String modelname;
void outing(){
System.out.println(“outing”);
}
public static void main(String args[])
{
tatacar z=new tatacar();
z.driving();
z.outing();
}
}

TBD:
By avoiding the first subclass output the program is running but other than the program shows error.