-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
39 lines (28 loc) · 717 Bytes
/
Copy pathApp.java
File metadata and controls
39 lines (28 loc) · 717 Bytes
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
package tutorial9;
class Person {
// class can have data
String name;
int age;
// class can have subroutines, known as class methods
void sayHello() {
System.out.println("hello" + " my name is " + name);
}
}
public class App {
public static void main(String[] args) {
// we make a bob instance of Person class
Person bob = new Person();
bob.name = "bob";
bob.age = 75;
// we make a joe instane of Person class
Person joe = new Person();
joe.name = "joe";
joe.age = 70;
System.out.println(joe.name);
System.out.println(joe.age);
System.out.println(bob.name);
System.out.println(bob.age);
// have the bob instance of Person use its sayHello method
bob.sayHello();
}
}