lecture-12 - CPSC 324 Topics in Java Programming Lecture 12...

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

2/24/10 1 CPSC 324 Topics in Java Programming Lecture 12 Today … NOTE -- Midterm : Thursday, March 4th Go over Quiz 4 More on constructors Exercise 6 Lab 3 (cont.) Readings: Ch. 8 pages 323-338 Ch. 9 pages 361-384 CPSC 324 ‐‐ Spring 2010 2
Image of page 1

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

2/24/10 2 Quiz 4 1. How would you implement the constructor for B so that x is set to anX and y is set to aY? public B(int anX, int aY) { super(anX); y = aY; } 2. Assume we want the getX() method in B to return “x+y”. How would you implement this method to return such a value? public int getX() { return super.getX() + getY(); } 3. What are the return values for the statements below? Mark those that result in compile errors. A a = new A(5); B b = new B(6, 10); a. C.add(a, a); b. C.add(a, b); c. C.add(b, a); d. C.add(b, b); CPSC 324 ‐‐ Spring 2010 3 10 // returns A’s getX() + A’s getX() 21 // returns A’s getX() + B’s getX() 21 // returns B’s getX() + A’s getX() 32 // returns B’s getX() + B’s getX() More on constructors Assume we have these classes: public class Animal { public Animal() { System.out.println(“Making an Animal”); } } public class Hippo extends Animal { public Hippo() { System.out.println(“Making a Hippo”); } } public class TestHippo { public static void main(String[] args) { System.out.println(“Starting…”); Hippo h = new Hippo(); } } CPSC 324 ‐‐ Spring 2010 4 What is output? $ java TestHippo Starting ... Making an Animal Making a Hippo $ java TestHippo Starting ...
Image of page 2
Image of page 3
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