Log in
Sign up for FREE
arrow_back
Library
Inheritance Quiz
By Mickey Arnold
star
star
star
star
star
Share
share
Last updated almost 2 years ago
10 questions
Add this activity
1
1
1
1
1
1
1
1
1
1
Question 1
1.
Which reserved word is used to indicate that one class is a child or descendant of another class?
implements
super
derives
extends
child
Question 2
2.
Consider the classes and client code below to determine what is printed by the client code.
public class N
{
private int one;
public N(){
one=5;
}
public String toString(){
return ""+ one;
}
}
public class O extends N
{
}
//client code
N it = new O();
System.out.println( it );
null
N
0
O
5
Question 3
3.
Consider the classes and client code below to determine the output of the client code.
public class N
{
private int one;
public N( int x ){
one=x;
}
public String toString(){
return ""+ one;
}
}
public class O extends N
{
public O( int x ){
super( x );
}
}
////////////////////////////////////////////////////////////////////////////
//client code
N it = new O(7);
System.out.println( it );
7
0
3
null
5
Question 4
4.
Consider the classes below and determine what is printed out by the client code.
public class V
{
public void one(){
System.out.print("it");
}
public void two(){
System.out.print("go");
}
}
public class W extends V
{
public void one(){
System.out.print("up");
}
public void two(){
System.out.print("at");
}
public void testIt(){
one();
super.two();
}
}
///////////////////////////////////////////////////////////////
//client code in the main of another class
V x = new V();
x.one();
null
up
at
go
it
Question 5
5.
Consider the classes below and determine what is printed out by the client code.
public class V
{
public void one(){
System.out.print("it");
}
public void two(){
System.out.print("go");
}
}
public class W extends V
{
public void one(){
System.out.print("up");
}
public void two(){
System.out.print("at");
}
public void testIt(){
one();
super.two();
}
}
///////////////////////////////////////////////////////////////
//client code in the main of another class
V x = new W();
x.one();
up
at
it
go
null
Question 6
6.
Consider the classes below and determine what is printed out by the client code.
public class V
{
public void one(){
System.out.print("it");
}
public void two(){
System.out.print("go");
}
}
public class W extends V
{
public void one(){
System.out.print("up");
}
public void two(){
System.out.print("at");
}
public void testIt(){
one();
super.two();
}
}
///////////////////////////////////////////////////////////////
//client code in the main of another class
V x = new W();
x.one();
x.two();
null
upgo
itat
itgo
upat
Question 7
7.
Consider the classes below and determine what is printed out by the client code.
public class V
{
public void one(){
System.out.print("it");
}
public void two(){
System.out.print("go");
}
}
public class W extends V
{
public void one(){
System.out.print("up");
}
public void two(){
System.out.print("at");
}
public void testIt(){
one();
super.two();
}
}
///////////////////////////////////////////////////////////////
//client code in the main of another class
V x = new W();
x.one();
x = new V();
x.two();
itgo
upat
itat
upgo
null
Question 8
8.
Consider the classes below and determine what is printed out by the client code.
public class V
{
public void one(){
System.out.print("it");
}
public void two(){
System.out.print("go");
}
public void testIt(){
one();
}
}
public class W extends V
{
public void one(){
System.out.print("up");
}
public void two(){
System.out.print("at");
}
public void testIt(){
one();
super.testIt();
super.one();
}
}
///////////////////////////////////////////////////////////////
//client code in the main of another class
W x = new W();
x.testIt();
itgoup
upitit
upupit
upupup
null
Question 9
9.
What is the output by the code below?
public class J
{
private int x, y;
public J() {
x = y = 4;
}
public void fun() {
x = y = 2;
}
public int back() {
return 7;
}
public String toString() {
return x + " " + y;
}
}
public class K extends J {
public void fun() {
System.out.print(back() + " ");
}
public String toString() {
return "" + super.toString();
}
}
//test code in a client program
J runner = new K();
System.out.println(runner);
4 4
7 2 2
2 2
null
7 4 4
Question 10
10.
What is the output by the code below?
public class J
{
private int x, y;
public J() {
x = y = 4;
}
public void fun() {
x = y = 2;
}
public int back() {
return 7;
}
public String toString() {
return x + " " + y;
}
}
public class K extends J {
public void fun() {
System.out.print(back() + " ");
}
public String toString() {
return "" + super.toString();
}
}
//test code in a client program
J runner = new K();
runner.fun();
System.out.println(runner);
4 4
null
2 2
7 4 4
7 2 2