-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
75 lines (63 loc) · 2.65 KB
/
Copy pathStudent.java
File metadata and controls
75 lines (63 loc) · 2.65 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
package Oops;
import java.util.Scanner;
class StudentInfo {
String Name;
int rollnum;
String Address;
String mob;
// StudentInfo(){ // defualt constructor which will be executed when the object
// is created...
// // this keyword will assign all these values once the object is created
// // so basically "this" keyword will replace thing written below...
// // S1.Name = "kunal";
// // S1.rollnum =12;
// // scan.nextLine(); // consume leftover newline
// // S1.Address = "kanput"; // full address
// // S1.mob =9912124;
// this.Name="Naman";
// this.rollnum=1;
// this.Address="Kanpur";
// this.mob="xxxxxxxxxxx";
// }
StudentInfo(StudentInfo other) {
this.Name = other.Name;
this.rollnum = other.rollnum;
this.Address = other.Address;
this.mob = other.mob;
}
StudentInfo(int roll, String Name, String add, String Mobile) {
this.Name = Name;
this.rollnum = roll;
this.Address = add;
this.mob = Mobile;
}
}
public class Student {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
StudentInfo S1 = new StudentInfo(58, "naman", "V21 yashoda nagar", "9912124411"); // here the constructor with
// three formal parameter will
// be called
// and if we write StudentInfo() without passing any values then the one with
// zero formal parameters will be called...
// System.out.println("Enter the info of 1st student::");
// StudentInfo S2 = new StudentInfo();
// S1.Name = "kunal";
// S1.rollnum =12;
// scan.nextLine(); // consume leftover newline
// S1.Address = "kanput"; // full address
// S1.mob =9912124;
System.out.println("The details of the first student is :: " +
S1.Name + " " + S1.rollnum + " " +
S1.Address + " " + S1.mob);
// System.out.println("The details of the second student is :: " +
// random.Name + " " + random.rollnum + " " +
// random.Address + " " + random.mob);
StudentInfo random = new StudentInfo(S1); // this will automatically call default one but if the default one is
// not there then
System.out.println("The details of the second student is :: " +
random.Name + " " + random.rollnum + " " +
random.Address + " " + random.mob);
scan.close();
}
}