15 - The CoopStudent class CS133 Developing Programming...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS133: Developing Programming Principles Lecture 15 More on Inheritance: super , final , method resolution, Object 2 The CoopStudent class public class CoopStudent extends Student { private boolean isOnWorkTerm = false; private static final double COOP_FEE = 317.69; public CoopStudent(String newName, int sID) { super(newName, sID); } public CoopStudent(String newName, String newAddress, int sID) { super(newName, newAddress, sID); } public double calcFees() { return super.calcFees() + COOP_FEE; } // other methods omitted } CS 133 Course Notes Lecture 15, Slide 2
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
3 Accessing the parent class Notice that we can use the constructor of Student – called super(newName, sID) Notice the method calcFees uses super in a different way – not as a constructor, but to indicate which class to look in for the (other) calcFees method Course Notes CS 133 Lecture 15, Slide 3 4 super as constructor Must be the first line in a constructor of a derived class. If it’s not there, Java automatically inserts super() as the first line. Must be super(Arguments) if superclass constructor needs parameters. CS 133 Course Notes Lecture 15, Slide 4
Image of page 2
5 Accessing the parent class continued • Using super as the name of the object will use the method defined in the parent (base) class.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern