{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

q2 - Triangle myTri myTri.width = 40 myTri.height = 50...

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

View Full Document Right Arrow Icon
Programming Fundamentals for CIS Majors II - CIS3023 (Summer 2010) Quiz -2 (24 May 2010) 1. Consider the following class: public class GradeBook { public static int a = 2; public int b = 100; } a. What are the class variables ? b. What are the instance variables ? c. What is the output from the following code fragment? GradeBook x = new GradeBook(); GradeBook y = new GradeBook(); x.b = 60; y.b = 85; x.a = 1; y.a = 2; System.out.println("x.b = " + x.b + "y.b = " + y.b); System.out.println("x.a = " + x.a + "y.a = " + y.a); System.out.println("GradeBook.a = " + GradeBook.a); c. Is the following code valid? If yes, what is the output after it? If no, why not? GradeBook.a++; System.out.println("GradeBook.a = " + GradeBook.a); GradeBook z = new GradeBook(); System.out.println("z.a = " + z.a); 2. What is wrong with the following program? public class GeometricShapes { public static void main(String[] args) { Triangle myTri;
Image of page 1

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

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

Unformatted text preview: Triangle myTri; myTri.width = 40; myTri.height = 50; System.out.println("myTriangle’s area is " + myTri.area()); } } 3. Given the Song class: class Song { String name; int seconds; double pricePerSecond; double price; final static double DEFAULT_PRICE = 0.010; Song(String n, int s, double p) { name = n; seconds = s; pricePerSecond = p; price = computePrice(); } Song(String n, int s) { this(n, s, DEFAULT_PRICE); } private double computePrice(){ return seconds * pricePerSecond; } } a. Write a Driver class, and within the main() create two song objects using each of the provided constructors. b. Modify the Song class to include a constructor with one parameter - the name, and with a default song length of five minutes. i. Can this constructor call the two-parameter constructor which in turn calls the three-parameter constructor? ii. Can a constructor call two other constructors, one after another?...
View Full 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