-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentObjects.java
More file actions
58 lines (40 loc) · 1.51 KB
/
Copy pathStudentObjects.java
File metadata and controls
58 lines (40 loc) · 1.51 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
public class StudentObjects {
private int rollNo;
private String name;
static int countStudents; // class variable or static variable or shared variable
StudentObjects(){
//initialize data members
}
StudentObjects(String nameParam ,int rollNo){ //parameterized contructor or overloaded constructor
name = nameParam;
this.rollNo = rollNo;
countStudents++;
System.out.println("Student count " +countStudents);
}
public String getName(){
return name;
}
public int getRollNo (){
return rollNo;
}
static void displayStaticMembers()
{
countStudents=20;
}
static
{
countStudents=20;
}
public static void main(String...args) {
StudentObjects studentObjects = new StudentObjects();
StudentObjects studentObj1 = new StudentObjects("Amit",1);
StudentObjects studentObj2 = new StudentObjects("Akhil",2);
StudentObjects studentObj3 = new StudentObjects("Akshit",3);
System.out.println("Student 1 Roll No " +studentObj1.getRollNo());
System.out.println("Student 1 Name " +studentObj1.getName());
System.out.println("Student 2 Roll No " +studentObj2.getRollNo());
System.out.println("Student 2 Name " +studentObj2.getName());
System.out.println("Student 3 Roll No " +studentObj3.getRollNo());
System.out.println("Student 3 Name " +studentObj3.getName());
}
}