Inheritance and Interfaces
Overview
Kotlin is an example of an ‘object-oriented programming’ language. You’ve used some objects before, but Kotlin forces you to really get into objects. Today, we’ll focus on the concepts core to “OOP”, which you’ll use heavily in Kotlin but apply across lots of other programming languages.
Basic Learning Objectives
Before class, you should be able to:
- Describe at a high level how classes can “inherit” code from another class
 - Describe the difference between an interface and a class
 
Advanced Learning Objectives
After class, you should be able to:
- Create a subclass
 - Implement an interface
 - Explain how instance variables work with inheritance
 
Readings
You should read the following:
Checks
You should submit answers to the following on the Gradescope assignment linked through Moodle. You may upload your answers in one file or different files and the name of the files doesn’t matter.
- 
    
Given the base class
Person, complete the derived classStudentbelow.Studentshould have the following properties:classYear: Student’s anticipated graduation yearmajor1: Student’s first major.major2: Student’s second major, if applicable.minor: A list of a student’s minors (because apparently, there isn’t a limit to the number of minors at Carleton…)
Studentshould have one member functiondeclareMajorthat:- sets 
major1to the declared major if the student’s first major is “Undeclared” - sets 
major2to the declared major if the student already has a first major but the student’s second major is “Undeclared” - prints “You have too many majors! Talk to your advisor.” if the student already two majors
 
 - 
    
Given the interface
RegistrarRecord, implement the member functionprintCoursesforStudentRecordandProfessorRecord.- Both 
StudentRecordandProfessorRecordshould have the same propertycourses, which is a list of courses. - However,  
printCoursesforStudentRecordfirst prints “I’m currently taking these courses:”, followed by the list of courses, whileprintCoursesforProfessorRecordfirst prints “I’m currently teaching these courses:” followed by the list of courses instead. 
 - Both