-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo9.java
More file actions
85 lines (61 loc) · 2.23 KB
/
Demo9.java
File metadata and controls
85 lines (61 loc) · 2.23 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// class Constructor {
// String name;
// int roll;
// public Constructor() { // Constructor name should be same as class name
// System.out.println("This is Constructor");
// }
// public constructor() {
// name = "Nothing";
// roll = 0;
// }
// }
// =============================================
// =============================================
// class newConstructor {
// String name;
// int roll;
// public newConstructor() { // Default Constructor
// name = "Nothing";
// roll = 0;
// }
// public newConstructor(String name, int roll) { // Parameterized Constructor
// this.name = name;
// this.roll = roll;
// }
// }
// =============================================
// =============================================
// class Anonymous {
// public Anonymous() {
// System.out.println("Object Created");
// }
// public void show() {
// System.out.println("SHOW");
// }
// }
public class Demo9 {
public static void main(String[] args) {
// 31. Constructor In Java
// Constructor std = new Constructor();
// System.out.println("The Name is: " + std.name + " & The Roll is: " +
// std.roll);
// std.name = "Tuman";
// std.roll = 20223045;
// System.out.println("The Name is: " + std.name + " & The Roll is: " +
// std.roll);
// =============================================
// =============================================
// 32. Default VS Parameterized Constructor In Java
// newConstructor newCtr = new newConstructor(); // Default Constructor
// System.out.println("The Name is: " + newCtr.name + " & The Roll is: " +
// newCtr.roll);
// newConstructor newCtr1 = new newConstructor("Tuman", 20223045); // Parameterized Constructor
// System.out.println("The Name is: " + newCtr1.name + " & The Roll is: " +
// newCtr1.roll);
// =============================================
// =============================================
// 33. Anonymous Object In Java
// new Anonymous(); // This is Anonymous Object
// new Anonymous().show();
}
}