-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructors.java
More file actions
48 lines (35 loc) · 831 Bytes
/
Copy pathconstructors.java
File metadata and controls
48 lines (35 loc) · 831 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
40
41
42
43
44
45
46
47
48
class human
{
int age;
String name;
public human()
{
name = "ayaan";
age = 20;
System.out.println("constructor called");
}
public human(int a, String str)
{
this.age = a;
this.name = str;
}
public void show()
{
System.out.println("called show method");
}
}
public class constructors {
public static void main(String[] args) {
human h1 = new human();
human h2 = new human();
System.out.println(h1.age + h1.name);
System.out.println(h2.age + h2.name);
human h3 = new human(25,"john");
System.out.println(h3.age + " " + h3.name);
System.out.println();
System.out.println();
//anonymous object
new human();
new human().show();
}
}