-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path62_Constructor7.java
More file actions
75 lines (66 loc) · 1.76 KB
/
62_Constructor7.java
File metadata and controls
75 lines (66 loc) · 1.76 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
/*
* Program of constructor overloading taking input from user
*/
package javaprograms;
import java.io.*;
/**
*
* @author Geeky Keshav
*/
public class Constructor7
{
static int roll;
static String name;
static String mob;
Constructor7(int r,String n,String m)
{
roll=r;
name=n;
mob=m;
}
Constructor7(int r,String n)
{
roll=r;
name=n;
}
void disp()
{
System.out.println("Roll no.: "+roll+", "+"Name: "+name);
System.out.println("*********************");
}
void disp1()
{
System.out.println("Roll no.: "+roll+", "+"Name: "+name+", "+"Mob: "+mob);
}
public static void main(String [] args)throws Exception
{
DataInputStream obj=new DataInputStream(System.in);
System.out.print("Enter Roll no.: ");
roll=Integer.parseInt(obj.readLine());
System.out.print("Enter Name: ");
name=obj.readLine();
Constructor7 obj1=new Constructor7(roll,name);
obj1.disp();
System.out.println("******************");
System.out.print("Enter Roll no.: ");
roll=Integer.parseInt(obj.readLine());
System.out.print("Enter Name: ");
name=obj.readLine();
System.out.print("Enter Mobile no.: ");
mob=obj.readLine();
Constructor7 obj2=new Constructor7(roll,name,mob);
obj2.disp1();
}
}
/*********OUTPUT*******
* run:
Enter Roll no.: 1
Enter Name: Geeky
Roll no.: 1, Name: Geeky
*********************
******************
Enter Roll no.: 2
Enter Name: Keshav
Enter Mobile no.: 7277674479
Roll no.: 2, Name: Keshav, Mob: 7277674479
*/