Preskoči na glavni sadržaj
Prijava
Sign up for FREE
arrow_back
Biblioteka

Inheritance Quiz

star
star
star
star
star
Posljednje ažuriranje about 2 years ago
10
1
1
1
1
1
1
1
1
1
1
Pitanje 1
1.

Which reserved word is used to indicate that one class is a child or descendant of another class?

Pitanje 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 );

Pitanje 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 );

Pitanje 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();

Pitanje 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();

Pitanje 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();

Pitanje 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();

Pitanje 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();

Pitanje 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);

Pitanje 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);