Inheritance Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
10 Questions
1 point
1
Question 1
1.
Which reserved word is used to indicate that one class is a child or descendant of another class?
Which reserved word is used to indicate that one class is a child or descendant of another class?
1 point
1
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 codeN it = new O();System.out.println( it );
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 );
1 point
1
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 codeN it = new O(7);System.out.println( it );
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 );
1 point
1
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 classV x = new V();x.one();
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();
1 point
1
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 classV x = new W();x.one();
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();
1 point
1
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 classV x = new W();x.one();x.two();
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();
1 point
1
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 classV x = new W();x.one();x = new V();x.two();
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();
1 point
1
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 classW x = new W();x.testIt();
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();
1 point
1
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 programJ runner = new K();System.out.println(runner);
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);
1 point
1
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 programJ runner = new K();runner.fun();System.out.println(runner);
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);