-
Notifications
You must be signed in to change notification settings - Fork 0
/
opps.java
47 lines (36 loc) · 1.01 KB
/
opps.java
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
class Pen{
String color;
String type; //functions which are define in class called as methods
public void write(){
System.out.println("writing something");
}
public void printColor(){
System.out.println(this.color); // this tell which object is accesing
}
}
class Student{
String name;
int age;
public void printInfo(){
System.out.println(this.name);
System.out.println(this.age);
}
}
//objects banate hai main function mai
public class opps {
public static void main(String args[]){
Pen pen1 = new Pen(); //object of pen class
pen1.color = "blue";
pen1.type = "gel";
Pen pen2 = new Pen();
pen2.color = "black";
pen2.type = "ballpoint";
pen1.write(); //to call object
pen1.printColor();
pen2.printColor();
Student s1 = new Student();
s1.name = "aman";
s1.age = 24;
s1.printInfo();
}
}