Repository navigation
Expand file tree
/
Copy pathUser.java
More file actions
55 lines (43 loc) · 1.39 KB
/
Copy pathUser.java
File metadata and controls
55 lines (43 loc) · 1.39 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
52
53
54
55
package constructor;
public class User {
// instance variable
String userName;
String password;
// ------------ Default Constructor --------------
// User(){
// userName = "test";
// password = "123";
// }
//
// ----------- parameterized constructor -----------
// User(String un, String psw){
// userName = un;
// password = psw;
// }
User(String userName, String password){
//this(); // calling default constructor
//this("aaa, "13"); // calling parameterized constructor
// if "this" is not used then the output will be null as local variable and instance variable gets conflicted bcz of having same name
this.userName = userName; // calling instance
this.password = password;
// this.printUser(); //calling instance method
// "this" keyword represent current object
// we can call instance variable, instance method and constructors.
}
void printUser() {
System.out.println("Username : "+userName);
System.out.println("Password : " +password);
}
public static void main(String[] args) {
// User u = new User(); // default
User u = new User("Aayush","777"); // parameterized
u.printUser();
/*
* -------- Object class (Parent class) ------------
* Class {@code Object} is the root of the class hierarchy.
* Every class has {@code Object} as a superclass. All objects,
* including arrays, implement the methods of this class.
*
*/
}
}