-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassObjects.java
More file actions
51 lines (40 loc) · 1.03 KB
/
ClassObjects.java
File metadata and controls
51 lines (40 loc) · 1.03 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
//Classes and Objects
class Pen { //Class 1
String color;
int price;
public void show() {
System.out.println(this.color);
System.out.println(this.price);
}
}
class Student {
String name;
int age;
public void info() {
System.out.println(this.name);
System.out.println(this.age);
}
}
public class ClassObjects {
public static void main(String... s) {
Pen p1 = new Pen(); //Object 1 of Class 1
p1.color = "Red";
p1.price = 880;
p1.show();
System.out.println();
Pen p2 = new Pen(); //Object 2 of Class 1
p2.color = "White";
p2.price = 1700;
p2.show();
System.out.println();
Student s1 = new Student();
s1.name = "Ram";
s1.age = 21;
s1.info();
System.out.println();
Student s2 = new Student();
s2.name = "Laxman";
s2.age = 20;
s2.info();
}
}