public class Course { private String courseNumber, courseTitle; public Course() { } public Course(String courseNumber, String courseTitle) { this.courseNumber = courseNumber; this.courseTitle = courseTitle; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseTitle(String courseTitle) { this.courseTitle = courseTitle; } public String getCourseNumber() { return courseNumber; } public String getCourseTitle() { return courseTitle; } public void printInfo() { System.out.println("Course Information: "); System.out.println(" Course Number: " + courseNumber); System.out.println(" Course Title: " + courseTitle); } } public class OfferedCourse extends Course { private String instructorName, location, classTime; public OfferedCourse() { } public OfferedCourse(String courseNumber, String courseTitle, String instructorName, String location, String classTime) { super(courseNumber, courseTitle); this.instructorName = instructorName; this.location = location; this.classTime = classTime; } public void setInstructorName(String instructorName) { this.instructorName = instructorName; } public void setLocation(String location) { this.location = location; } public void setClassTime(String classTime) { this.classTime = classTime; } public String getInstructorName() { return instructorName; } public String getLocation() { return location; } public String getClassTime() { return classTime; } } the code is correct but need fix the Space
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
public class Course {
private String courseNumber, courseTitle;
public Course()
{
}
public Course(String courseNumber, String courseTitle) {
this.courseNumber = courseNumber;
this.courseTitle = courseTitle;
}
public void setCourseNumber(String courseNumber) {
this.courseNumber = courseNumber;
}
public void setCourseTitle(String courseTitle) {
this.courseTitle = courseTitle;
}
public String getCourseNumber() {
return courseNumber;
}
public String getCourseTitle() {
return courseTitle;
}
public void printInfo() {
System.out.println("Course Information: ");
System.out.println(" Course Number: " + courseNumber);
System.out.println(" Course Title: " + courseTitle);
}
}
public class OfferedCourse extends Course {
private String instructorName, location, classTime;
public OfferedCourse() {
}
public OfferedCourse(String courseNumber, String courseTitle, String instructorName, String location, String classTime) {
super(courseNumber, courseTitle);
this.instructorName = instructorName;
this.location = location;
this.classTime = classTime;
}
public void setInstructorName(String instructorName) {
this.instructorName = instructorName;
}
public void setLocation(String location) {
this.location = location;
}
public void setClassTime(String classTime) {
this.classTime = classTime;
}
public String getInstructorName() {
return instructorName;
}
public String getLocation() {
return location;
}
public String getClassTime() {
return classTime;
}
}
the code is correct but need fix the Space
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images