Write a program for multilevel inheritance such that country is inherited from continent. State is inherited from country. Display the place, state, country and continent.
State.java
import java.io.*;
class Continent
{
String con;
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
void con() throws IOException
{
System.out.println("Enter name of Continent :");
con=r.readLine();
}
}
class Country extends Continent
{
String cou;
void cou() throws IOException
{
System.out.println("Enter name of Country :");
cou=r.readLine();
}
}
class State extends Country
{
String sta;
void sta() throws IOException
{
System.out.println("Enter name of State :");
sta=r.readLine();
}
public static void main(String [] args) throws IOException
{
State s=new State();
s.con();
s.cou();
s.sta();
System.out.println("\n\nContinent :"+s.con);
System.out.println("Country :"+s.cou);
System.out.println("State :"+s.sta);
}
}
Comments
Post a Comment