-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstructor.java
More file actions
43 lines (37 loc) · 1.01 KB
/
Constructor.java
File metadata and controls
43 lines (37 loc) · 1.01 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
//Two types of Constructor
//Default constructor
//Parameterized constructor
//####################################### Default constructor ###############################################
public class Constructor
{
Constructor() //Defalut Constructor
{
System.out.println("This is default Contructor");
}
public static void main(String[] args)
{
Constructor cons = new Constructor();
}
}
//####################################### Default constructor ###############################################
public class Constructor
{
int id;
String name;
Constructor(int iid, String nam) //Parameterized Constructor
{
id = iid;
name = nam;
}
void display()
{
System.out.println("Id is: "+id+" Name is: "+name);
}
public static void main(String[] args)
{
Constructor obj = new Constructor(20, "Juned");
Constructor obj1 = new Constructor(25, "Adnan");
obj.display();
obj1.display();
}
}