Question 1mediummultiple choice
Read the full Object-Oriented Programming explanation →1Z0-811 Object-Oriented Programming • Complete Question Bank
Complete 1Z0-811 Object-Oriented Programming question bank — all 0 questions with answers and detailed explanations.
Refer to the exhibit.
public class Employee {
private String name;
public Employee(String name) { this.name = name; }
public String getName() { return name; }
}
public class Manager extends Employee {
private int teamSize;
public Manager(String name, int teamSize) {
super(name);
this.teamSize = teamSize;
}
}Refer to the exhibit.
interface Printable {
default void print() { System.out.println("Printable"); }
}
interface Showable {
default void print() { System.out.println("Showable"); }
}
class Document implements Printable, Showable {
// no override
}Drag steps to the numbered slots on the right, or tap a step then tap a slot.
Drag a concept onto its matching description — or click a concept then click the description.
Runtime exception (unchecked)
Checked exception
Runtime exception (unchecked)
Checked exception
Runtime exception (unchecked)
public class Vehicle { protected int speed; public Vehicle() { speed = 0; } public void accelerate() { speed += 10; } } public class Car extends Vehicle { public void accelerate() { speed += 20; } }public class Test { public static void main(String[] args) { Animal a = new Animal(); a.sound(); } } abstract class Animal { abstract void sound(); }public class Singleton { private static Singleton instance; private Singleton() {} public static Singleton getInstance() { if (instance == null) { instance = new Singleton(); } return instance; } }class Parent { void show() { System.out.print("Parent"); } }
class Child extends Parent { void show() { System.out.print("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }What is the output?
Refer to the exhibit.
What is the output?
class Vehicle {
String type = "Vehicle";
}
class Car extends Vehicle {
String type = "Car";
}
public class Test {
public static void main(String[] args) {
Vehicle v = new Car();
System.out.println(v.type);
}
}Refer to the exhibit.
What is the output?
interface Printable {
void print();
}
class Document implements Printable {
public void print() { System.out.println("Document"); }
}
class Photo extends Document {
public void print() { System.out.println("Photo"); }
}
public class Test {
public static void main(String[] args) {
Document d = new Photo();
d.print();
}
}Refer to the exhibit.
What is the likely cause?
javac Test.java
Test.java:5: error: cannot find symbol
System.out.println(value);
^
symbol: variable value
location: class TestConsider the following Java class:
public class Employee {
private String name;
public Employee(String name) {
name = name;
}
public String getName() {
return name;
}
}class Animal {
public void sound() {
System.out.println("Animal sound");
}
}
class Dog extends Animal {
public void sound() {
System.out.println("Bark");
}
public void fetch() {
System.out.println("Fetching");
}
}
public class Test {
public static void main(String[] args) {
Animal a = new Dog();
a.sound();
((Dog) a).fetch();
}
}