Return in elephanttester when testing aresiblings

This preview shows page 3 - 7 out of 12 pages.

return } In ElephantTester, when testing areSiblings, need to test calls like areSiblings(m1, null ) areSiblings( null , m2)
Image of page 3

Subscribe to view the full document.

4 Content of this lecture This lecture contains some final miscellaneous points to round out your knowledge of classes and subclasses. There are a few more things to learn after this, but we’’ll handle them much later. Inheriting fields and methods and Overriding methods. Sec. 4.1 and 4.1.1: pp. 142–145 Purpose of super and this . Sec. 4.1.1, pp. 144–145. More than one constructor in a class; another use of this . Sec. 3.1.3, pp. 110–112. Method equals in class Object. Sec. 4.3 and 4.3.1, pp. 154–155. (We do not cover the method at the end of Sec. 4.3.1.) Constructors in a subclass —calling a constructor of the super-class. Sec. 4.1.3, pp. 147–148.
Image of page 4
5 public class Employee {/** Instance: a person's name, year hired, and salary */ private String name; // Employee's name private int start; // Year hired private double salary= 50000; // Salary /** Constructor: a person with name n, year hired d, salary s */ public Employee(String n, int d) { name= n; start= d; salary= s;} /** = name of this Employee */ public String getName() { return name; } /** Set the name of this Employee to n */ public void setName(String n) { name= n; } /** = year this Employee was hired */ public int getStart() { return start; } /** Set the year this Employee was hired to y */ public void setStart( int y) { start= y; } /** = Employee's total compensation (here, the salary) */ public double getCompensation() { return salary; } /** Change this Employee’s salary to d */ public void changeSalary(double d) { salary= d; } /** = String representation of this Employee */ public String toString() { return getName() + ", year " + getStart() + ", salary " + salary; } } This class is on page 105 of the text.
Image of page 5

Subscribe to view the full document.

6 Employee c= new Employee(“Gries”, 1969, 50000); c.toString() a0 Object name “Gries” start 1969 salary 50,000.00 getName() setName(String n) toString() equals(Object) toString() Employee c a0 Which method toString() is called? Overriding rule: To find out which is used, start at the bottom of the class and search upward until a matching one is found.
Image of page 6
Image of page 7
You've reached the end of this preview.

{[ 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