ITSC 1213 COMPREHENSIVE QUESTIONS AND
ANSWERS SET A+
✔✔Given the following class definitions which of the following would not compile if it
was used in place of the missing code in the main method?
***
Parent Class
class Item
{
private int x;
public void setX(int theX)
{
x = theX;
}
// ... other methods not shown
}
Child Class
public class EnhancedItem extends Item
{
private int y;
public void setY(int theY)
{
y = theY;
}
// ... other methods not shown
public static void main(String[] args)
{
EnhancedItem currItem = new EnhancedItem();
// missing code
}
} - ✔✔currItem.x = 3;
, ✔✔A program is being written by a team of programmers. One programmer is
implementing a class called Employee; another programmer is writing code that will use
the Employee class. Which of the following aspects of the public methods and fields of
the Employee class does not need to be known by both programmers? - ✔✔How the
methods are implemented.
✔✔What is the output from running the main method in the Car class?
public class Car
{
private int fuel;
public Car()
{
fuel = 0;
}
public Car(int g)
{
fuel = g;
}
public void addFuel()
{
fuel++;
}
public void display()
{
System.out.print(fuel + " ");
}
public static void main(String[] args)
{
Car car = new Car(5);
Car fastCar = new RaceCar(5);
car.display();
car.addFuel();
car.display();
fastCar.display();
fastCar.addFuel();
fastCar.display();
}
}
class RaceCar extends Car
{
public RaceCar(int g)
{
super(2*g);
}
} - ✔✔NOT 5656
ANSWERS SET A+
✔✔Given the following class definitions which of the following would not compile if it
was used in place of the missing code in the main method?
***
Parent Class
class Item
{
private int x;
public void setX(int theX)
{
x = theX;
}
// ... other methods not shown
}
Child Class
public class EnhancedItem extends Item
{
private int y;
public void setY(int theY)
{
y = theY;
}
// ... other methods not shown
public static void main(String[] args)
{
EnhancedItem currItem = new EnhancedItem();
// missing code
}
} - ✔✔currItem.x = 3;
, ✔✔A program is being written by a team of programmers. One programmer is
implementing a class called Employee; another programmer is writing code that will use
the Employee class. Which of the following aspects of the public methods and fields of
the Employee class does not need to be known by both programmers? - ✔✔How the
methods are implemented.
✔✔What is the output from running the main method in the Car class?
public class Car
{
private int fuel;
public Car()
{
fuel = 0;
}
public Car(int g)
{
fuel = g;
}
public void addFuel()
{
fuel++;
}
public void display()
{
System.out.print(fuel + " ");
}
public static void main(String[] args)
{
Car car = new Car(5);
Car fastCar = new RaceCar(5);
car.display();
car.addFuel();
car.display();
fastCar.display();
fastCar.addFuel();
fastCar.display();
}
}
class RaceCar extends Car
{
public RaceCar(int g)
{
super(2*g);
}
} - ✔✔NOT 5656