forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructorExample.java
More file actions
37 lines (31 loc) · 868 Bytes
/
ConstructorExample.java
File metadata and controls
37 lines (31 loc) · 868 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
package com.examplehub.basics.oop;
public class ConstructorExample {
public static void main(String[] args) {
ConstructorTest test = new ConstructorTest();
System.out.println(test); /* ConstructorTest{username='admin', password='112233'} */
test = new ConstructorTest("root", "root");
System.out.println(test); /* ConstructorTest{username='root', password='root'} */
}
}
class ConstructorTest {
public String username;
public String password;
public ConstructorTest() {
this("admin", "112233");
}
public ConstructorTest(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public String toString() {
return "ConstructorTest{"
+ "username='"
+ username
+ '\''
+ ", password='"
+ password
+ '\''
+ '}';
}
}