Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Given the following class declarations: public class Car { private String make; public Car(String theMake) { make = theMake; } public String getMake() {

1. Given the following class declarations: public class Car { private String make; public Car(String theMake) { make = theMake; } public String getMake() { return make; } } public class ElectricCar extends Car { public ElectricCar() { super("Ford"); } public ElectricCar(String theMake) { super(theMake); } } Which of the following will cause a compile time error? Given the following class declarations: public class Car { private String make; public Car(String theMake) { make = theMake; } public String getMake() { return make; } } public class ElectricCar extends Car { public ElectricCar() { super("Ford"); } public ElectricCar(String theMake) { super(theMake); } } Which of the following will cause a compile time error? Car myCar4 = new ElectricCar("Toyota"); Car myCar3 = new Car("Ford"); Car myCar = new Car(); ElectricCar myCar2 = new ElectricCar("Ford"); Car myCar1 = new ElectricCar();

2. Consider the following code segment and three classes. ClassA item1 = new ClassA(); ClassA item2 = new ClassB(); ClassA item3 = new ClassC(); ArrayList items = new ArrayList(); items.add(item1); items.add(item2); items.add(item3); for (ClassA item: items) item.showClass(); public class ClassA { public ClassA() { } public void showClass() {System.out.println("Class A");} } public class ClassB extends ClassA { public ClassB() { } public void showClass() {System.out.println("Class B");} } public class ClassC extends ClassB { public ClassC() { } } What is printed as a result of executing the code segment? Consider the following code segment and three classes. ClassA item1 = new ClassA(); ClassA item2 = new ClassB(); ClassA item3 = new ClassC(); ArrayList items = new ArrayList(); items.add(item1); items.add(item2); items.add(item3); for (ClassA item: items) item.showClass(); public class ClassA { public ClassA() { } public void showClass() {System.out.println("Class A");} } public class ClassB extends ClassA { public ClassB() { } public void showClass() {System.out.println("Class B");} } public class ClassC extends ClassB { public ClassC() { } } What is printed as a result of executing the code segment? Class A Class A Class A Class B Class B Class A Class B Class C Class A Class B Class A Class A Class B

3. A subclass's method can explicitly call a superclass's method. True False

4. Consider the following CircusPerformer class declaration. public class CircusPerformer { private String performerName; private String actName; public CircusPerformer(String pN, String aN) { performerName = pN; actName = aN; } public String getPerformer() { return performerName; } public String getAct() { return actname; } public void act() { entrance(); performance(); exit(); } public void entrance() { System.out.println("Starts in ring center"); } public void performance() { System.out.println("Runs in circles"); } public void exit() { System.out.println("Exits from ring center"); } } Consider the following code segment and incomplete Equestrian class. Equestrian sue = new Equestrian("Sue", "Amazing Ponies"); sue.act(); public class Equestrian extends CircusPerformer { } An Equestrian object is a CircusPerformer who rides ponies over obstacles. Which of the following methods must be defined in the Equestrian class? I. Equestrian constructor II. act III. entrance IV. performance V. exit

5. Consider the following program statement and three classes Employee juan = new Employee("Plumber", 45000, "Juan", 29, 14, "Associates"); public class Car { private int year; private String make; public Car (int y, String m) { year = y; make = m; System.out.println("Car is instantiated"); } } public class Person { private String name; private int age; private Car car; public Person(String n, int a, int y, String m) { name = n; age = a; car = new Car(y, m); System.out.println("Person is instantiated"); } } public class Employee extends Person { private String job; private double salary; public Employee(String j, double x, String n, int a, int y, String m) { super(n, a, y, m); job = j; salary = x; System.out.println("Employee is instantiated"); } } What is printed as a result of executing the program statement? Person is instantiated Employee is instantiated Employee is instantiated Car is instantiated Person is instantiated Employee is instantiated Employee is instantiated Person is instantiated Car is instantiated Employee is instantiated Person is instantiated

6. Consider the following code segment and two classes. Person sue = new Person(25); Student tom = new Student(17, 12); System.out.println(sue.getAge()); System.out.println(tom.getGrade()); public class Person { private int age; public Person(int a) { age = a; System.out.println("Person Constructor"); } public int getAge() { return age; } } public class Student extends Person { private int grade; public Student(int g, int a) { super(a); grade = g; System.out.println("Student Constructor"); } public int getGrade() { return grade; } } What are the first 2 lines of program output? Consider the following code segment and two classes. Person sue = new Person(25); Student tom = new Student(17, 12); System.out.println(sue.getAge()); System.out.println(tom.getGrade()); public class Person { private int age; public Person(int a) { age = a; System.out.println("Person Constructor"); } public int getAge() { return age; } } public class Student extends Person { private int grade; public Student(int g, int a) { super(a); grade = g; System.out.println("Student Constructor"); } public int getGrade() { return grade; } } What are the first 2 lines of program output? Student constructor Student constructor Student constructor Person constructor Person constructor Student constructor 25 17 Person constructor Person constructor

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started