-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractical_22.java
More file actions
76 lines (64 loc) · 2.03 KB
/
Practical_22.java
File metadata and controls
76 lines (64 loc) · 2.03 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
/*Question := Write a program of constructor overloading and make zero argument constructor
to set a default values of student name, roll no and total marks. And make
another constructor with all the three parameters and make use of ‘this’
keyword. Using methods, display values of both the constructors.*/
import java.util.Scanner;
public class Practical_22 {
String name;
int enroll;
int marks;
Practical_22() {
this.name = "Jainam";
System.out.println(this.name);
this.enroll = 2101201075;
this.marks = 488;
}
Practical_22(String name, int enroll, int marks) {
this.name = name;
this.enroll = enroll;
this.marks = marks;
}
public void display() {
System.out.println(name);
System.out.println(enroll);
System.out.println(marks);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Practical_22 p1 = new Practical_22();
System.out.println("Before Updating := ");
p1.display();
System.out.println("=======================================");
System.out.println("For Update := ");
System.out.println("Enter Name of Student :=");
String name = sc.nextLine();
System.out.println("Enter Enrollment No. :=");
int enroll = sc.nextInt();
System.out.println("Enter Total Marks :=");
int marks = sc.nextInt();
Practical_22 p2 = new Practical_22(name, enroll, marks);
System.out.println("=======================================");
System.out.println("After Updating := ");
p2.display();
}
}
/*
Output :=
Before Updating :=
Jainam
2101201075
488
=======================================
For Update :=
Enter Name of Student :=
John
Enter Enrollment No. :=
2101201205
Enter Total Marks :=
79
=======================================
After Updating :=
John
2101201205
79
*/