Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 3

Total questions: 19

Worksheet time: 10mins

Name
Class
Date
1.

TJ04_01. What is the output of the following program? Be precise about where there are spaces and where there are newlines.

public class Ex4_1{

public static void zoop() {

baffle();

System.out.print("you foo ");

baffle(); }

public static void main(String[] args) {

System.out.print("No, I ");

zoop();

System.out.print("I ");

baffle(); }

public static void baffle() {

System.out.print("baz");

ping(); }

public static void ping() {

System.out.println("."); } }

a)

the program doesn't stop

b)

No, I baz.
you foo baz.
I baz.

c)

none of the other choices is correct

d)

you foo baz.
No, I baz.
I baz.

e)

you foo baz.
No, I baz.
I baz.

2.

TJ04_02. What is the output of the following program?

public class Ex4_2{

public static void zoop() {

baffle();

System.out.print("you foo ");

baffle(); }

public static void main(String[] args) {

System.out.print("No, I ");

zoop();

System.out.print("I ");

baffle(); }

public static void baffle() {

System.out.print("baz");

ping(); }

public static void ping() {

System.out.println(".");

baffle(); } }

a)

you foo baz.
No, I baz.
I baz.

b)

none of the other choices is correct

c)

the program doesn't stop

d)

No, I baz.
you foo baz.
I baz.

e)

you foo baz.
No, I baz.
I baz.

3.

TJ04_03. Choose what would be the correct first line of a method named zool that takes three parameters: an int and two Strings.

a)

none of the other choices is correct

b)

 

    public void zool(int i, String s1, String s2)

c)

 

    public void zool(int i, String s1, s2)

d)

 

    public  zool(int i , String ss, String ss)

e)

 

    public void zool(int, Str, Str)

4.

TJ04_04. Identify the line of code that calls a method named zool, that takes three parameters: an int and two Strings, passing as arguments the value 11, the String "hello" and the String "world".

a)

 

    public void zool(11,"hello","world")

b)

 

zool(11, hello, world)

c)

 

 zool(int, Str, Str)

d)

 

none of the other choices is correct

e)

 

zool(11,"hello", "world")

5.

TJ04_06. Suppose you have a static method called printAmerican that takes the month (e.g. "July"), day (e.g. 23), year (e.g. 2018), and day of the week (e.g. "Thursday") as parameters and displays them in American format (e.g. Thursday, July 23, 2018).  Which one of the following programs calls the method correctly to print the date.

a)

public class PrintAmerican{

    //method diefition goes here

    public static void main(String[] aaa){

        PrintAmerican("July", 23, 2018, "Thursday");

    }

}

b)

PrintAmerican.PrintAmerican("July", 23, 2018, "Thursday");

c)


public class PrintAmerican{

    

    //method definition goes here

    

    public static void main(String[] aaa){

        main.PrintAmerican("July", 23, 2018, "Thursday");

    }

}

d)

 

none of the other choices is correct

e)


public class PrintAmerican{

    

    //method definition goes here

    

    public static void foo(String[] aaa){

        PrintAmerican("July", 23, 2018, "Thursday");

    }

}

6.

TJ04_07. in the following code the print statements  are numbered (the numbers look like //1, //2, //3, //4)

list the numbers in the order in which they are executed.

public class foo{
    public static void main(String[] args) {
        zippo("foo");
        System.out.println("foo");//1
        baffle("zoo");
    }
    public static void baffle(String blimp) {
        System.out.println(blimp);//2
    }
    public static void zippo(String quince) {
        System.out.println(quince);//3
        System.out.println(quince);//4
    }
}

a)

 

3142

b)

 

none of the other answers is correct

c)

3412

d)

1324

e)

3124

7.

TJ04_08. in order to use the Math class you must first import the package that contains it.

a)

True

b)

False

8.

TJ04_09. One of the methods of the class Math is called atan.

a)

True

b)

False

9.

TJ04_11. The largest possible long is 922,337,203,685

a)

True

b)

False

10.

how much is 2 multiplied by itself 20 times?

a)

 

2097152.0

b)

1048576.0

c)

4194304.0

d)

524288.0

e)

 

none of the other answers is correct

11.

TJ04_13.  each class can have only one method

a)

True

b)

False

12.

TJ04_14. what is a reason to use methods

a)

A common problem solving technique is to break tasks down into sub-problems.

b)

all the answers shown here are reasons to use methods

c)

Introducing new methods can make a program smaller by eliminating repetitive code

d)

Creating a new method gives you an opportunity to give a name to a group of statements, which makes code easier to read and understand.

13.

TJ04_16. what is printed by this program

 

class foo{
    public static void zonk(String st1, String st2, String st3){
        System.out.print(st3 + " " + st1 + " " + st2 + "\n");
    }

    public static void main(String[] args) {
        zonk("this","method has","three arguments");
    }
}

a)

method has this three arguments

b)

this method has three arguments

c)

three arguments this method has

d)

this three arguments method has

e)

 

none of the other answers is correct

14.

TJ04_17. the print statements of this program have been numbered (\\1,\\2,\\3,\\4).  In what order are they executed

class foo{
    public static void zonk1(String st){
        System.out.print(st);//1
    }
    public static void zonk2(String st){
        System.out.print(st);//2
    }
    public static void zonk3(String st){
        System.out.print(st);//3
    }

    public static void main(String[] args) {
        zonk2("foo");
        zonk3("foo");
        zonk1("foo");
        System.out.println();//4
    }
}

a)

1234

b)

2314

c)

2134

d)

2314

e)

4132

15.

TJ04_18. Suppose we have a method mm(int x).

that contains only the following statement:

x = 5;

what is printed if the main method has the following statements:

        int x = 10;

        mm(x);
        System.out.println(x);

a)

 

it is a compile time error

b)

 

it is a runtime error

c)

 

10

d)

 

none of the other answers is correct

16.

TJ04_19. Suppose we have a method mm(int y).

that contains only the following statement:

System.out.print(x);

what is printed if the main method only has the following statements:

        int x = 10;

        mm(x);
        System.out.println(x);

a)

 

10

b)

 

1010

c)

 

it is a compile time error

d)

 

none of the other answers is correct

17.

TJ04_21.  

Suppose a class has the following method:

    public static void printTime(int x) {
        hour = 3*hour;
        System.out.print(hour);
    }

if the main method of the class contains the following code:

    public static void main(String[] args) {
        int hour = 1;
        printTime(hour);
        System.out.println(hour);
    }

what would the main method print when it is executed.

a)

31

b)

 

11

c)

 

none of the other answers is correct

d)

 

it is a compile time error

18.

TJ04_22. Javadoc 

a)

 

is another java compiler

b)

 

it compiles java documents

c)

 

none of the other answers is correct

d)

 

it uses a different java virtual machine

e)

 

is a document generator tool in Java programming language for generating standard documentation in HTML format

19.

TJ04_24. Consider following code.  In what order are the methods executed?

public class TJ04_24 {
    public static void A(){
        D();
        G();
    }
    public static void B(){
    }
    public static void C(){
        B();
        F();
    }
    public static void D(){
    }
    public static void E(){
        A();
        C();
    }
    public static void F(){
        D();
    }
    public static void G(){
        B();
    }
    public static void main(String[] args) {
        E();
    }
}

a)

 

mainEADGBCBFD

b)

 

none of the other answers is correct

c)

 

mainEAGDBCFBD

d)

 

it doesn't end normally

e)

 

ADGBCBFDEACFDGBmainE