Question
Answer the correct option. Question 5 What can an abstract class contain? Question 5 options: constructors, instance variables, instance methods, abstract methods, static methods, static
Answer the correct option.
Question 5
What can an abstract class contain?
Question 5 options:
constructors, instance variables, instance methods, abstract methods, static methods, static variables | |
constructors, instance variables, instance methods, abstract methods, | |
abstract methods, static methods, static variables | |
instance variables, instance methods, abstract method |
Question 6
What is the use of the keyword super in a subclass?
Question 6 options:
It provides access to the constructor of the superclass. | |
It provides access to an instance method of the superclass. | |
It provides access to a public instance variable of the superclass. | |
All of the above. | |
None of the above |
Question 7
What is the purpose of a constructor in a subclass.
Question 7 options:
To initialize value of the subclasses' private and public instance variable through assignment statements (eg. this.x = 1) | |
To initialize the value of the subclasses' public and private instance variables and the superclasses' private and public instance variables through assignment statements. (super.x = 1; this.y = 2) | |
To use a super constructor to initialize the value of the superclasses' instance variables. | |
To initialize value of the subclasses' private and public instance variable through assignment statements (eg. this.x = 1) and use a super constructor to initialize the value of the superclasses' instance variables. |
Question 8
Abstract classes can not be instantiated.
Question 8 options:
True | |
False |
Question 9
Which of the following is a correct implementation of polymorphism. Note, object B extends object A.
Question 9 options:
B obj1 = new A(); | |
A ob1 = new A(); | |
B obj1 = new B(); | |
A obj1 = new B(); |
Question 10
Interfaces differ from Abstract class because:
Question 10 options:
a class can implement many interfaces, but can only extend one abstract class | |
abstract classes create a hierarchy but interfaces do not | |
interfaces can only contain abstract methods and no implementations | |
all of the above |
Question 11
Given this code snippet,
public class Person { public String name; public Person(String name) { System.out.println(name); this.name = name; } public void printName() { System.out.println(this.name); } } public class Miner extends Person { public Miner(String name) { super(name); } }
what will this program print?
Person somePerson = new Person("Bob"); Miner mikeTheMiner = new Miner("Mike"); mikeTheMiner.printName();
Question 11 options:
This code causes an error. | |
Mike Mike Bob | |
Bob Mike Mike | |
Bob | |
Bob Mike Bob |
Question 12
Based on this code snippet
public class Shape { public String getShapeName() { return "Shape"; } } public class Rectangle extends Shape {} public class Square extends Rectangle {} public class Oval extends Shape { public String getShapeName() { return "Oval"; } } public class Circle extends Oval { public String getShapeName() { return "Circle"; } }
what does this program output?
Shape shape1 = new Shape(); Shape shape2 = new Rectangle(); Shape shape3 = new Square(); Shape shape4 = new Circle(); System.out.println(shape1.getShapeName()); System.out.println(shape2.getShapeName()); System.out.println(shape3.getShapeName()); System.out.println(shape4.getShapeName());
Question 12 options:
Shape Rectangle Rectangle Circle | |
Shape Shape Shape Shape | |
Shape Shape Shape Circle | |
This code will error | |
Shape Rectangle Square Circle | |
Shape Rectangle Rectangle Oval |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started