COMP2150Winter2016termtest_solutions.pdf

COMP2150Winter2016termtest_solutions.pdf - COMP 2150 Object...

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

COMP 2150 Object Orientation Term Test 1 February 5, 2016 page 1 of 4 Student Number: ____________________ ( put your name on the back page ) Instructions 1. Make sure your Student number is written above. Put your name on the back of the package. 2. Answer all questions on the paper. 3. No aids permitted (e.g., no calculators, no books); turn cell phones off, and keep them out of sight. 4. Time allotted: 50 minutes. Total marks: 20. Predict the output Inheritance Short Answer Java Programming Total /3 /6 /4 /7 /20 Section A: Predict the output (3x1 mark) For each of the following code blocks, write the output on the right-hand side. You can assume that any import or include statements are present in the code to ensure proper compilation. Note that the first block is in Java while the second and third are in C++. class C {public String me() {return “C”;}} class D extends C { public String me() { return “D”; } } public class Q1 { public static void main (String[] args) { C c = new C(); System.out.print(c.me() + " "); D d = new D(); System.out.print(d.me()); } } C D class A { protected: int y; public: A() { y = 2; } virtual int stuff() { return y;} }; class B: public A { public: B() { } int stuff() { return 2*y;} }; int main() { B bee; A ayy = bee; cout << ayy.stuff() <<" "<< bee.stuff();
Image of page 1

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

Image of page 2
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '14
  • boyer

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