THE OCA EXAM TOPICS COVERED IN THIS PRACTICE TEST INCLUDE THE FOLLOWING:
How many lines of the following program contain compilation errors? Which modifier can be applied to an abstract interface method? What is the output of the following application? Which of the following statements about inheritance is true? Given the class declaration below, which value cannot be inserted into the blank line that would allow the code to compile? Imagine you are working with another team to build an application. You are developing code that uses a class that the other team has not finished writing yet. Which element of Java would best facilitate this development, allowing easy integration once the other team’s code is complete? What is the output of the following application? Which of the following statements about inheritance is correct? How many changes need to be made to the classes below to properly override the watch() method? Which of the following statements about overriding a method is incorrect? What is the output of the following application? Given that FileNotFoundException is a subclass of IOException, what is the output of the following application? Which modifier can be applied to an interface method? What is the output of the following application? Which of the following statements about interfaces is not true? What is the output of the following application? Fill in the blanks: Excluding default and static methods, a(n) ____________can contain both abstract and concrete methods, while a(n) ____________contains only abstract methods. Which statement about the following class is correct? Given that Short and Integer extend Number, what type can be used to fill in the blank in the class below to allow it to compile? Fill in the blanks: A class ____________an interface, while a class ____________an abstract class. What is the output of the following application? The following diagram shows two reference variables pointing to the same Bunny object in memory. The reference variable myBunny is of type Bunny, while unknownBunny is of an unknown data type. Which statement about the reference variables is not true? For this question, assume the instance methods and variables shown in the diagram are marked public. Which of the following modifiers can be applied to an abstract method? What is the output of the following application? Which of the following statements is correct? Of the following four modifiers, choose the one that is not implicitly applied to all interface variables. What is the output of the following application? Fill in the blank: Overloaded and overridden methods always have____________ . What is the output of the following application? Fill in the blanks: A class that defines an instance variable with the same name as a variable in the parent class is referred to as ____________a variable, while a class that defines a static method with the same signature as a static method in a parent class is referred to as ____________a method. Which statement about the following class is correct? What is the output of the following application? Fill in the blanks: A class may be assigned to a(n) _____________ reference variable automatically but requires an explicit cast when assigned to a(n) _____________ reference variable. Fill in the blank: A(n) ____________is the first non-abstract subclass that is required to implement all of the inherited abstract methods. How many compiler errors does the following code contain? Which of the following is not an attribute common to both abstract classes and interfaces? What is the output of the following application? Which of the following is a virtual method? Fill in the blanks: An interface ____________another interface, while a class ____________another class. What is the output of the following application? Given the following method and the fact that FileNotFoundException is a subclass of IOException, which of the following method signatures is a valid override by a subclass? Given the class definitions below, which value, when inserted into the blank line, does not allow the class to compile? Which of the following modifiers cannot be applied to an interface method? Which statement about the following application is true? Fill in the blanks: ____________methods must have a different list of parameters, while ____________methods must have the exact same return type. Which of the following statements about no-argument constructors is correct? Fill in the blanks: The ____________determines which attributes exist in memory, while the ____________determines which attributes are accessible by the caller. Given that Integer and Long are subclasses of Number, what type can be used to fill in the blank in the class below to allow it to compile? Which of the following is the best reason for creating a default interface method? Given that EOFException is a subclass of IOException, what is the output of the following application?
package theater;
class Cinema {
private String name;
public Cinema(String name) {this.name = name;}
}
public class Movie extends Cinema {
public Movie(String movie) {}
public static void main(String[] showing) {
System.out.print(new Movie("Another Trilogy").name);
}
}
package radio;
public class Song {
public void playMusic() {
System.out.print("Play!");
}
private static int playMusic() {
System.out.print("Music!");
}
public static void main(String[] tracks) {
new Song().playMusic();
}
}
package mammal;
interface Pet {}
public class Canine implements Pet {
public ___________ getDoggy() {
return this;
}
}
package vehicles;
class Automobile {
private final String drive() { return "Driving vehicle"; }
}
class Car extends Automobile {
protected String drive() { return "Driving car"; }
}
public class ElectricCar extends Car {
public final String drive() { return "Driving electric car"; }
public static void main(String[] wheels) {
final Car car = new ElectricCar();
System.out.print(car.drive());
}
}
package entertainment;
class Television {
protected final void watch() {}
}
public class LCD extends Television {
Object watch() {}
}
package machines;
class Computer {
protected final int process() { return 5; }
}
public class Laptop extends Computer {
public final int process() { return 3; }
public static void main(String[] chips) {
System.out.print(new Laptop().process());
}
}
package edu;
import java.io.*;
class School {
public int getNumberOfStudentsPerClassroom(String... students) throws IOException {
return 3;
}
public int getNumberOfStudentsPerClassroom() throws IOException {
return 9;
}
}
public class HighSchool extends School {
public int getNumberOfStudentsPerClassroom() throws FileNotFoundException {
return 2;
}
public static void main(String[] students) throws IOException {
School school = new HighSchool();
System.out.print(school.getNumberOfStudentsPerClassroom());
}
}
package track;
interface Run {
default void walk() {
System.out.print("Walking and running!");
}
}
interface Jog {
default void walk() {
System.out.print("Walking and jogging!");
}
}
public class Sprint implements Run, Jog {
public void walk() {
System.out.print("Sprinting!");
}
public static void main() {
new Sprint().walk();
}
}
package transport;
class Ship {
protected int weight = 3;
private int height = 5;
public int getWeight() { return weight; }
public int getHeight() { return height; }
}
public class Rocket extends Ship {
public int weight = 2;
public int height = 4;
public void printDetails() {
System.out.print(super.getWeight()+","+super.height);
}
public static final void main(String[] fuel) {
new Rocket().printDetails();
}
}
package shapes;
abstract class Triangle {
abstract String getDescription();
}
class RightTriangle extends Triangle {
protected String getDescription() { return "rt"; } // g1
}
public abstract class IsoscelesRightTriangle extends RightTriangle { // g2
public String getDescription() { return "irt"; }
public static void main(String[] edges) {
final Triangle shape = new IsoscelesRightTriangle(); // g3
System.out.print(shape.getDescription());
}
}
package band;
interface Horn { public Integer play(); }
abstract class Woodwind { public Short play() {return 3;} }
public final class Saxophone extends Woodwind implements Horn {
public ___________play() {
return null;
}
}
package paper;
abstract class Book {
protected static String material = "papyrus";
public Book() {}
public Book(String material) {this.material = material;}
}
public class Encyclopedia extends Book {
public static String material = "cellulose";
public Encyclopedia() {super();}
public String getMaterial() {return super.material;}
public static void main(String[] pages) {
System.out.print(new Encyclopedia().getMaterial());
}
}
package space;
interface Sphere {
default String getName() { return "Unknown"; }
}
abstract class Planet {
abstract String getName();
}
public class Mars extends Sphere implements Planet {
public Mars() {
super();
}
public String getName() { return "Mars"; }
public static void main(final String[] probe) {
System.out.print(((Planet)new Mars()).getName());
}
}
package race;
abstract class Car {
static { System.out.print("1"); }
public Car(String name) {
super();
System.out.print("2");
}
{ System.out.print("3"); }
}
public class BlueCar extends Car {
{ System.out.print("4"); }
public BlueCar() {
super("blue");
System.out.print("5");
}
public static void main(String[] gears) {
new BlueCar();
}
}
package sports;
abstract class Ball {
protected final int size;
public Ball(int size) {
this.size = size;
}
}
interface Equipment {}
public class SoccerBall extends Ball implements Equipment {
public SoccerBall() {
super(5);
}
public Ball get() { return this; }
public static void main(String[] passes) {
Equipment equipment = (Equipment)(Ball)new SoccerBall().get();
System.out.print(((SoccerBall)equipment).size);
}
}
package shapes;
abstract class Parallelogram {
private int getEqualSides() {return 0;}
}
abstract class Rectangle extends Parallelogram {
public static int getEqualSides() {return 2;} // x1
}
public final class Square extends Rectangle {
public int getEqualSides() {return 4;} // x2
public static void main(String[] corners) {
final Square myFigure = new Square(); // x3
System.out.print(myFigure.getEqualSides());
}
}
package flying;
class Rotorcraft {
protected final int height = 5;
abstract int fly();
}
public class Helicopter extends Rotorcraft {
private int height = 10;
protected int fly() {
return super.height;
}
public static void main(String[] unused) {
Helicopter h = (Helicopter)new Rotorcraft();
System.out.print(h.fly());
}
}
package animal;
interface CanFly {
public void fly() {}
}
final class Bird {
public int fly(int speed) {}
}
public class Eagle extends Bird implements CanFly {
public void fly() {}
}
package musical;
interface SpeakDialogue { default int talk() { return 7; } }
interface SingMonologue { default int talk() { return 5; } }
public class Performance implements SpeakDialogue, SingMonologue {
public int talk(String... x) {
return x.length;
}
public static void main(String[] notes) {
System.out.print(new Performance().talk(notes));
}
}
class Math {
public final double secret = 2;
}
class ComplexMath extends Math {
public final double secret = 4;
}
public class InfiniteMath extends ComplexMath {
public final double secret = 8;
public static void main(String[] numbers) {
Math math = new InfiniteMath();
System.out.print(math.secret);
}
}
protected void dance() throws FileNotFoundException {}
public class Canine {}
public class Dog extends Canine {}
public class Wolf extends Canine {}
public final class Husky extends Dog {}
public class Zoologist {
Canine animal;
public final void setAnimal(Dog animal) { this.animal = animal; }
public static void main(String[] furryFriends) {
new Zoologist().setAnimal(_____________);
}
}
package party;
abstract class House {
protected abstract Object getSpace();
}
abstract class Room extends House {
abstract Object getSpace(Object list);
}
abstract public class Ballroom extends House {
protected abstract Object getSpace();
public static void main(String[] squareFootage) {
System.out.print("Let's start the party!");
}
}
package orchestra;
interface MusicCreator { public Number play(); }
abstract class StringInstrument { public Long play() {return 3L;} }
public class Violin extends StringInstrument implements MusicCreator {
public _____________ play() {
return 12;
}
}
package ai;
import java.io.*;
class Machine {
public boolean turnOn() throws EOFException {return true;}
}
public class Robot extends Machine {
public boolean turnOn() throws IOException {return false;}
public static void main(String[] doesNotCompute) throws Exception {
Machine m = new Robot();
System.out.print(m.turnOn());
}
}