-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (31 loc) · 861 Bytes
/
Main.java
File metadata and controls
39 lines (31 loc) · 861 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 src;
public class Main {
// username variable.
private String userName;
// Default contractor.
Main() {
userName = "";
}
// Overloaded src.constructor.
Main(String userName) {
this.userName = userName;
}
// accessor or getter method.
public String getUserName() {
return this.userName;
}
// mutator or setter method.
public void setUserName(String userName) {
this.userName = userName;
}
// main driven function.
public static void main(String[] args) {
// creating src.first user.
var user1 = new Main();
user1.setUserName("Muhammad Naveed");
System.out.println(user1.getUserName());
// creating second user.
var user2 = new Main("M Naveed");
System.out.println(user2.getUserName());
}
}