-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaCity.java
More file actions
66 lines (66 loc) · 1.61 KB
/
Copy pathaCity.java
File metadata and controls
66 lines (66 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*write a java Program to illustrate multilevel inheritance such that is inherited from country. City is inherited from state. Display city, state and country. Write constructor , appropriate setter and getter methods.*/
import java.util.Scanner;
class Country{
private String countryname;
//default constructor
Country(){
countryname="";
}
Country(String countryname){
this.countryname=countryname;
}
public void SetCountry(String c){
this.countryname=c;
}
public String getCountry(){
return this.countryname;
}
}
class State extends Country{
private String statename;
State(){
super();
statename="";
}
State(String countryname, String statename){
super(countryname);
this.statename=statename;
}
public void SetState(String s){
this.statename=s;
}
public String getState(){
return this.statename;
}
}
class City{
private String cityname;
City(){
super();
cityname="";
}
City(String countryname, String statename, String cityname){
super(countryname,statename);
this.cityname=cityname;
}
public void setCity(String ci){
this.cityname=ci;
}
public String getCity(){
return this.cityname;
}
void display(){
System.out.println("Country name is "+getCountry());
System.out.println("State name is "+getState());
System.out.println("City is "+getCity());
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("please enter country state and city");
String c=sc.nextLine();
String s=sc.nextLine();
String ci=sc.nextLine();
City C=new City(c,s,ci);
C.display();
}
}