forked from maheshashokit/27_Java_Full_Stack_Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
45 lines (35 loc) · 1.21 KB
/
Course.java
File metadata and controls
45 lines (35 loc) · 1.21 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
public class Course {
//Instance Fields
private int courseId;
private String courseName;
//Define Constructor
public Course() {
System.out.println("Course Class public Constructor with No Parameters....");
}
//Defining the Parameterized Constructor
//Constructor Local Field & Instance Field Names are same
public Course(int courseId,String courseName) {
this.courseId = courseId;
this.courseName = courseName;
}
//Defining the method with Parameters
public void assignValues(int courseId,String courseName) {
this.courseId = courseId;
this.courseName = courseName;
}
//Defining the method for display
public void displayCourseInfo() {
System.out.println("Course ID :::::" + courseId);
System.out.println("Course Name :::::" + courseName);
}
public static void main(String[] args) {
//Creating the Object
Course c = new Course(); //public constructor with no parameter
//calling method
c.assignValues(12,"CoreJava"); //method call
c.displayCourseInfo(); //method call
System.out.println("*********************************************");
Course c1 = new Course(16,"SpringBoot"); //parameterized constructor get executed
c1.displayCourseInfo();
}
}