-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClassMethod.java
More file actions
33 lines (28 loc) · 842 Bytes
/
ClassMethod.java
File metadata and controls
33 lines (28 loc) · 842 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
class Class2{
int var;
String str;
// Method 1: insertValues
void insertValues(int v,String s){
var = v;
str = s;
}
// Method 2: displayValue
void displayValue(){
System.out.println(var);
System.out.println(str);
}
}
class ClassMethod {
public static void main(String[] args) {
Class2 object1 = new Class2();
Class2 object2 = new Class2();
object1.insertValues(100,"Programming in Java");
// object.insertValues(500,"Java is OOP Language");
object1.displayValue();
// To display another value
// We have to define another object so that second value doesn't overlap the first value
System.out.println();
object2.insertValues(200,"Java is an OOP language ");
object2.displayValue();
}
}