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

Writing Classes Test Multiple Choice Part 1-60%

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

What is output by the code below?

public class CS

{

public void one()

{

System.out.print("one");

two(true);

}

private void two(boolean stop)

{

System.out.print("two");

if(!stop)

one();

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.one();

Pitanje 2
2.

What is output by the code below?

public class CS

{

public void one()

{

System.out.print("one");

two(true);

}

public void two(boolean stop)

{

System.out.print("two");

if(!stop)

one();

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.two(false);

Pitanje 3
3.

What is output by the code below?

public class CS

{

public void one()

{

System.out.print("one");

two(true);

}

public void two(boolean stop)

{

System.out.print("two");

if(!stop)

one();

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.one();

Pitanje 4
4.

What is output by the code below?

public class CS

{

int q = 0;

public void go(int i)

{

if(i==0)

q++;

for(int j = 0;j<i;j++)

go2(i-1);

}

public void go2(int i)

{

if(i==0)

q++;

for(int j = 0;j<i;j++)

go(i-1);

}

public int getQ()

{

return q;

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.go(2);

System.out.println( test.getQ() );

Pitanje 5
5.

What is output by the code below?

class CS

{

int q = 0;

public void go(int i)

{

if(i==0)

q++;

for(int j = 0;j<i;j++)

q+=2;

}

public int getQ()

{

return q;

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.go(11);

System.out.println( test.getQ() );

Pitanje 6
6.

What is output by the code below?

public class CS

{

int q = 0;

public void go(int i)

{

if(i==0)

q++;

for(int j = 0;j<i;j++)

go2(i-1);

}

public void go2(int i)

{

if(i==0)

q++;

for(int j = 0;j<i;j++)

go(i-1);

}

public int getQ()

{

return q;

}

}

///////////////////////////////////////////////////////////

//code in the main of another class

CS test = new CS();

test.go(4);

System.out.println( test.getQ() );

Pitanje 7
7.

Consider the class and statements that follow.

public class Dog

{

private String voice;

public void setVoice( String v )

{

voice = v;

}

public void barkOnce()

{

System.out.print( voice );

}

public void barkTwice()

{

barkOnce();

barkOnce();

}

}

Given the declaration below, which of the following are valid statements?

Dog d = new Dog();

d.setVoice( "roof" );

I.

d.barkOnce();

II.

d.barkTwice("rrrrrr");

III.

System.out.println( d.barkTwice() );

Pitanje 8
8.

Consider the class and statements that follow.

public class Dog

{

private String voice;

public void setVoice( String v )

{

voice = v;

}

public void barkOnce()

{

System.out.print( voice );

}

public void barkTwice()

{

barkOnce();

barkOnce();

}

}

Given the declaration below, which of the following are valid statements?

Dog d = new Dog();

d.setVoice( "roof" );

I.

d.barkOnce();

II.

d.barkTwice();

III.

System.out.println( d.barkTwice() );

Pitanje 9
9.

Consider the class and statements that follow.

public class Dog

{

private String voice;

public void setVoice( String v )

{

voice = v;

}

public void barkOnce()

{

System.out.print( voice );

}

public void barkTwice()

{

barkOnce();

barkOnce();

}

}

Given the declaration below, which of the following are valid statements?

Object d = new Dog();

I.

d.barkOnce();

II.

d.barkTwice("rrrrrr");

III.

System.out.println( d.barkTwice() );

Pitanje 10
10.

Consider the class and statements that follow.

public class Dog

{

private String voice;

public void setVoice( String v )

{

voice = v;

}

private void barkOnce()

{

System.out.print( voice );

}

public void barkTwice()

{

barkOnce();

barkOnce();

}

public String toString()

{

return voice;

}

}

Given the declaration below, which of the following are valid statements?

Object d = new Dog();

((Dog)d).setVoice( "roof" );

I.

d.barkOnce();

II.

((Dog)d).barkTwice();

III.

System.out.println( d );

Pitanje 11
11.

Consider the class and client code below.

public class Aplus

{

public double go( double a ){

return a * 3;

}

public double fun( double b ){

return go( b ) + b;

}

}

//client code in another class

Aplus x = new Aplus();

System.out.println( x.go(2) );

Pitanje 12
12.

Consider the class and client code below.

public class Aplus

{

public double go( double a ){

return a * 3;

}

public double fun( double b ){

return go( b ) + b;

}

}

//client code in another class

Aplus x = new Aplus();

System.out.println( x.go(3) );

Pitanje 13
13.

Consider the class and client code below.

public class Aplus

{

public double go( double a )

{

return a * 3;

}

public double fun( double b )

{

return go( b ) + b;

}

}

//client code in another class

Aplus x = new Aplus();

System.out.println( x.fun(3) );

Pitanje 14
14.

Consider the class and statements that follow.

public class Money

{

private double amount;

public Money(double am)

{

amount = am;

}

public void addQuarters(int q)

{

amount += q * 0.25;

}

public void addDimes(int d)

{

amount += d * 0.1;

}

public double getAmount()

{

return amount;

}

}

What is the output of the code below?

Money m = new Money(.3);

m.addQuarters(3);

m.addDimes(6);

m.addQuarters(4);

System.out.println(m.getAmount());

Pitanje 15
15.

Consider the class and statements that follow.

public class Money

{

private double amount;

public Money(double am)

{

amount = am;

}

public void addQuarters(int q)

{

amount += q * 0.25;

}

public void addDimes(int d)

{

amount += d * 0.1;

}

public double getAmount()

{

return amount;

}

}

What is the output of the code below?

Money m = new Money(2.1);

m.addDimes(7);

m.addQuarters(7);

m.addDimes(2);

System.out.println(m.getAmount());

Pitanje 16
16.

What is output by the code below?

public class Check

{

private int fun;

public void change()

{

int fun = 5;

}

public String toString()

{

return "" + fun;

}

}

//client code

Check test = new Check();

test.change();

out.println(test);

Pitanje 17
17.

What is output by the code below?

public class Check

{

private int fun;

public void change()

{

fun = 5;

int fun = 6;

}

public String toString()

{

return "" + fun;

}

}

//client code

Check test = new Check();

test.change();

out.println(test);

Pitanje 18
18.

What is output by the code below?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

}

public String toString()

{

return "" + total;

}

}

//code in the main of another class

Check test = new Check();

test.setNums(3,-6);

test.add();

out.println(test);

Pitanje 19
19.

What is output by the code below?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

two = 5;

}

public String toString()

{

total = 2;

return "" + total;

}

}

//code in the main of another class

Check test = new Check();

test.setNums(-6,3);

test.add();

out.println(test);

Pitanje 20
20.

What is output by the code below?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

one = 5;

total = one + two;

two = 5;

}

public String toString()

{

return "" + total;

}

}

//code in the main of another class

Check test = new Check();

test.setNums(3,2);

test.add();

out.println(test);

Pitanje 21
21.

How many modifier methods are there in class Check?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

one = 5;

total = one + two;

two = 5;

}

public String toString()

{

return "" + total;

}

}

Pitanje 22
22.

How many instance variables are there in class It?

public class It

{

private int val;

}

Pitanje 23
23.

How many methods are there in class It?

public class It

{

private int val;

public It()

{

val = 7;

}

public int getIt()

{

return val;

}

}

Pitanje 24
24.

How many methods are there in class It?

public class It

{

private int val;

public It()

{

val = 7;

}

public int getIt()

{

return val;

}

}

Pitanje 25
25.

How many accessor methods are there in class It?

public class It

{

private int val;

public It()

{

val = 7;

}

public int getIt()

{

return val;

}

}

Pitanje 26
26.

What is output by the code below?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

}

public int getTotal()

{

return total;

}

}

//code in the main of another class

Check test = new Check();

test.setNums(3,-6);

test.add();

out.println(test.getTotal());

Pitanje 27
27.

How many modifier / mutator methods are there in class Check?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

}

public int getTotal()

{

return total;

}

}

Pitanje 28
28.

How many instance variables are there in class Check?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

}

public int getTotal()

{

return total;

}

}

Pitanje 29
29.

How many constructors are there in class Check?

public class Check

{

private int one, two, total;

public void setNums(int n1, int n2)

{

one = n1;

two = n2;

}

public void add()

{

total = one + two;

}

public int getTotal()

{

return total;

}

}

Pitanje 30
30.

Consider the class and client code below.

public class Aplus

{

public double go( double a )

{

return a * 3;

}

public double fun( double b )

{

return b * 2;

}

}

//client code in another class

Aplus x = new Aplus();

System.out.println( x.fun(6) );

Pitanje 31
31.

What is output by the code below?

public static void aMethod(int a){

a=9;

a=7;

}

//test code

int aParam = 4;

aMethod(aParam);

out.println(aParam);

Pitanje 32
32.

What is output by the code below?

public static void bMethod(int b){

b=9;

out.print(b+" ");

b=7;

}

//test code

int bParam = 4;

bMethod(bParam);

out.println(bParam);

Pitanje 33
33.

What is output by the code below?

public static void cMethod(int c){

c=9;

c=7;

out.print(c+" ");

}

//test code

int cParam = 4;

cMethod(cParam);

out.println(cParam);

Pitanje 34
34.

What is output by the code below?

public static void addStuff(int d, int c)

{

System.out.println(c + " + " + d + " = " + (c+d));

}

///////////////////////////////////////////////////////////////////////////////////////

//client code in the main of a runner class

int a = 32;

int b = 9;

addStuff(a,b);

Pitanje 35
35.

What is output by the code below?

public static void withdraw(double balance, double amount)

{

balance -= amount;

}

///////////////////////////////////////////////////////////////////////////////////////

//client code in the main of a runner class

double balance = 1020.37;

double amount = 350;

withdraw(balance, amount);

System.out.println(balance);

Pitanje 36
36.

What is output by the following code?

public static void test(Integer x, int y)

{

x += y;

}

///////////////////////////////////////////////////////////////////////////////////////

//client code in the main of a runner class

Integer i = new Integer(4);

test(i,5);

System.out.println(i);

Pitanje 37
37.

What is output by the code below?

public class A

{

private int one;

public A(int o){

one=o;

}

public void setOne(int o){

one = o;

}

public int getOne(){

return one;

}

}

public class B

{

public void changeOne(A param){

param=new A(0);

param.setOne(7);

}

public void changeTwo(A param){

param.setOne(4);

}

public void changeThree(A param){

param.setOne(9);

param=new A(0);

}

}

//code in the main of another class

B test = new B();

A theA = new A(2);

test.changeOne(theA);

out.println(theA.getOne());

Pitanje 38
38.

What is output by the code below?

public class A

{

private int one;

public A(int o){

one=o;

}

public void setOne(int o){

one = o;

}

public int getOne(){

return one;

}

}

public class B

{

public void changeOne(A param){

param=new A(0);

param.setOne(7);

}

public void changeTwo(A param){

param.setOne(4);

}

public void changeThree(A param){

param.setOne(9);

param=new A(0);

}

}

//code in the main of another class

B test = new B();

A theA = new A(2);

test.changeTwo(theA);

System.out.println(theA.getOne());

Pitanje 39
39.

What is output by the code below?

public class A

{

private int one;

public A(int o){

one=o;

}

public void setOne(int o){

one = o;

}

public int getOne(){

return one;

}

}

public class B

{

public void changeOne(A param){

param=new A(0);

param.setOne(7);

}

public void changeTwo(A param){

param.setOne(4);

}

public void changeThree(A param){

param.setOne(9);

param=new A(0);

}

}

//code in the main of another class

B test = new B();

A theA = new A(2);

test.changeThree(theA);

System.out.println(theA.getOne());

Pitanje 40
40.

What is output by the code below?

String a = "aplus";

String b = a;

b = null;

System.out.println( a );