-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaConcepts.java
More file actions
163 lines (154 loc) · 3.51 KB
/
JavaConcepts.java
File metadata and controls
163 lines (154 loc) · 3.51 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package JavaTutorials;
import java.util.ArrayList;
// Denonstrates OOPS concepts
// person class - super class
class Person {
//common variables
private String name;
private String address;
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @return the name
*/
public String getName() {
return name;
}
public void schedule(String[] days){
System.out.println("Person class schedule doesn't call this method when using subclass");
}
}
// student class
class Student extends Person{
//student class variables
private int id;
private String college;
//constructors
public Student() {
super();
}
/**
* @param college the college to set
*/
public void setCollege(String college) {
this.college = college;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the college
*/
public String getCollege() {
return college;
}
/**
* @return the id
*/
public int getId() {
return id;
}
// schedule method
@Override
public void schedule(String[] days){
System.out.print(getName() +" has Classes on");
for (String day : days)
System.out.print(", "+day);
System.out.println(".");
}
}
// employee class
class Employee extends Person{
// employee specific variables
private int employeeID;
private String company;
// constructors
public Employee(){
super();
}
/**
* @param company the company to set
*/
public void setCompany(String company) {
this.company = company;
}
/**
* @param employeeID the employeeID to set
*/
public void setEmployeeID(int employeeID) {
this.employeeID = employeeID;
}
/**
* @return the employeeID
*/
public int getEmployeeID() {
return employeeID;
}
/**
* @return the company
*/
public String getCompany() {
return company;
}
// schedule method
@Override
public void schedule(String[] days){
System.out.print(getName() +" goes to Work on");
for (String day : days)
System.out.print(", "+ day);
System.out.println(".");
}
}
// main class
public class JavaConcepts {
public static void main(String[] args) {
String[] days = {"Monday", "Friday"};
//Student object
Student tom = new Student();
tom.setName("tom");
tom.setAddress("66 aaa");
tom.setId(11);
tom.setCollege("sheridan");
tom.schedule(days);
//Employee Object
Employee jim = new Employee();
jim.setName("Jim");
jim.setAddress("66 aaa");
jim.setEmployeeID(11);
jim.setCompany("sheridan");
jim.schedule(days);
//Student object through Person class
Person tim = new Person();
tim.setName("tim");
tim.setAddress("66 aaa");
// will throw an error
//tim.setId(11);
tim.schedule(days);
ArrayList<Person> al = new ArrayList<Person>();
al.add(tom);
al.add(jim);
al.add(tim);
for ( Person a : al){
System.out.println(a.getClass());
}
}
}