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

Info iconThis 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) {
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background 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("myTriangles 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

This note was uploaded on 05/27/2011 for the course CIS 3023 taught by Professor Dobbins during the Summer '08 term at University of Florida.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online