-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
24 lines (20 loc) · 864 Bytes
/
Copy pathCourse.java
File metadata and controls
24 lines (20 loc) · 864 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
class Course {
String courseName;
String courseCode;
// Constructor using "this" keyword to differentiate between class attributes and parameters
public Course(String courseName, String courseCode) {
this.courseName = courseName; // "this.courseName" refers to the class attribute
this.courseCode = courseCode; // "this.courseCode" refers to the class attribute
}
// Method to display course details
void displayCourseDetails() {
System.out.println("Course Name: " + this.courseName);
System.out.println("Course Code: " + this.courseCode);
}
public static void main(String[] args) {
// Creating an object of Course class
Course course1 = new Course("OOPS", "OJ101");
// Displaying course details
course1.displayCourseDetails();
}
}