Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Questions 1-3 are based upon the following code: public class Test { public stat

ID: 3866244 • Letter: Q

Question

Questions 1-3 are based upon the following code:

public class Test

{

        public static void main(String[] args)

      {

                System.out.println( multi(5) );

        }

        public static int multi(int n)

        {

                System.out.println(n);

                return n * n;

        }

}

1. What does the following program display?

a. The program displays 25.

b. The program displays 25 followed by 5.

c. The program displays 5 followed by 25.

d. The program displays 5 followed by 25 followed by 25.

2. True or false?

The Test class has two method definitions.

3. multi is a(n) ______________.

a. void method

b. class

c. static method

d. object

Questions 4-6 are based on the following code:

public static void nPrint(String message, int n)

{

      while (n > 0)

      {

                System.out.print(message);

                n--;

      }

}

4. The above code is an example of:

a. A variable declaration

b. A while loop

c. A class definition

d. A method definition

5. What is the printout of the call:     nPrint("a", 4);

a. aaaaa

b. aaaa

c. aaa

d. aa

6.

What is the value of the identifier k after the following code fragment is evaluated?

                int k = 2;

                nPrint("A message", k+1);

a. 0

b. 1

c. 2

d. 3

7.

Analyze the following code.

public class Test

{

      public static void main(String[] args)

      {

                int n = 2;

                xMethod(n);

                System.out.println("n is " + n);

      }

      public static void xMethod(int n)

      {

                n++;

      }

}

a. The code prints n is 0.

b. The code prints n is 1.

c. The code prints n is 2.

d.The code prints n is 3.

8. Which of the following is false about using methods.

a. Using methods makes a program run faster.

b. Using methods makes reusing code easier

c. Using methods makes programs easier to read.

d. Using methods hides detailed implementation from the client who calls the method.

9. Which of the following is false about the constructor method of a class

a. It can be overloaded.

b. It is always called after the keyword create.

c. The name of the constructor is the same as the class.

d. It may be sent any number of actuals, depending upon the definition.

10.

Which of the following is NOT an example of instantiating an object.

a. Keyboard k;
k = new Keyboard( );

b. InputFile infile = new InputFile( fn );

c. String s = “abcd”;

d. int x = 100;

Explanation / Answer

[1] Answer: [C] The program displays 5 followed by 25
Explaination : First Print in Local Method then print in Main method.

[2] False
Explaination : It's having only one Method Defination which is Multi(int n)

[3] Answer : [C] Static Method
Explaination : Method name start with Static Keyword.

[4] Answer : [B] A whlie Loop

[5] Answer : [B] aaaa
Explaination : While loop execute only 4 time

[6] Answer: [C] 2

[7] Answer : [C] n is 2
Explaination : Call by Value do't effect the local variable value.

[8] Answer : [C] Using methods makes reusing code easier

[9] Answer : [B]
Explaiantion : only called after NEW keyword.

[10[ Answer : [D]
Explaiantion : only create primative data type not an object.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote