-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththis_keyword.java
More file actions
37 lines (34 loc) · 1010 Bytes
/
this_keyword.java
File metadata and controls
37 lines (34 loc) · 1010 Bytes
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
package NPTEL1;
//class student
class Student{
int roll_no;
String name,course;
float fee;
//constructor including three arguments
Student(int roll_no,String name,String course){
this.roll_no=roll_no;
this.name=name;
this.course=course;
}
//constructor including one more argument 'fee'
Student(int roll_no,String name, String course,float fee){
//for reusing the any constructor in other constructor
this(roll_no,name,course);//reusing the above constructor
this.fee=fee;// here the fee with this belong to the student class
}
// method to display
void display() {
System.out.println(roll_no+" "+name+" "+course+" "+fee);
}
}
//main class
public class this_keyword {
public static void main (String[]args ) {
//objects initialized by two different
Student s1=new Student(05,"akash","java");
Student s2=new Student(15,"raju","c++",5000f);
//calling display method
s1.display();
s2.display();
}
}