-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructor.java
More file actions
48 lines (28 loc) · 901 Bytes
/
Copy pathConstructor.java
File metadata and controls
48 lines (28 loc) · 901 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{
String name;
int age;
//This is the Constructor
//Constructor will have no return type
//It will have the same name as the class name
public Human(){
name = "Partha";
age = 90;
System.out.println("This is the message from the Constructor");
}
//Parameterized Constructor
public Human(String name, int age){
this.name = name;
this.age = age;
System.out.println(name+" : "+age);
}
public void show(){
System.out.println(name+" : "+age);
}
}
class Constructor{
public static void main(String[] args){
Human h=new Human(); //Default Constructor will be called here
h.show(); //This will print the default values set by the Constructor above
Human h1=new Human("Aditya Singh", 24); //Parameterized Constructor will be called here
}
}