-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStudent.java
More file actions
66 lines (62 loc) · 1.83 KB
/
Student.java
File metadata and controls
66 lines (62 loc) · 1.83 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
// SRP
// Functionality
public class Student { //extends Object{
// by default the scope is default scope with in the package
//private is used to define the scope and the scope is limited to the class
private int rollno; //Instance Variable
private String name;
private String courseName;
private byte age;
private final String collegeName;
/*
* What is Constructor
* It is used to initalize the Instance Variables and it is call when u create an object
* Constructor Name is same as Class Name
* U Can't Create Object with out calling Constructor
* Constructor Doesn't have return type
*/
// Every Class has Default Constructor By Default
// It is Empty By Default and It is Doing Nothing
// Default Constructor
private Student(){
//this(100,"ABCD","BCA",(byte)21);
collegeName="SRCC";
/*rollno =10;
name="Some Name";
courseName = "MCA";
age = 21;*/
}
// Constructor Overloading
// Create More than one constructor with different arguments
// Parameterized Constructor
Student(int rollno , String name, String courseName, byte age){
this(); // Constructor Calling ( It Must be On First Line)
//Student();
this.rollno = rollno ;
this.name = name;
this.courseName = courseName;
this.age = age;
}
// Assign Local Variables into Instance Variables
public void takeInput(int rollno , String name , String courseName , byte age){
if(rollno<=0){
System.out.println("Rollno Can't Be Zero or Negative....");
return ;
}
this.rollno = rollno;
this.name = name;
this.courseName = courseName;
this.age = age;
}
void print(){
// this is a keyword and it hold the current reference
System.out.println( "Rollno "+this.rollno );
System.out.println( "Name "+this.name );
System.out.println( "Course "+courseName );
System.out.println( "Age "+age);
System.out.println("College Name "+collegeName);
}
public int hashCode(){
return 100;
}
}