Which of the following is NOT a primitive data type in Java?  Which of the following lines declares a constant holding the value 42 in Java?Java Programming

SECTION A

 Answers for this section must be written on the multiple-choice answer sheet (machine-readable form).

 Question 1 [2%]

 Which of the following is NOT a primitive data type in Java?

 

  • char 

  • double 

  • int 

  • number

  

Question 2 [2%]

 What output will be produced by the following Java program?

boolean a = true; boolean b = false; a = a && b;

b = ! b;

System.out.println(a + " " + b); 

 

  • false false

  • false true

  • true false

  • true true

 

Question 3 [2%]

 What output will be produced by the following Java program?

int a = 1; int b = 1;

while (a * b < 10) { a += b;

if (a == 4)

continue;

b++;

}

System.out.println(a + b);

 

  • 7

  • 8

  • 9

  • 10

 Question 4 [2%]

 Which of the following lines declares a constant holding the value 42 in Java?

 

  • static final int ANSWER = 42;

  • static const int ANSWER = 42;

  • static final ANSWER = 42;

  • static const ANSWER = 42;


Question 5

 A programmer has written a method which takes as its argument an array of integers and returns a new array with the same elements but in reverse order. Unfortunately one of the lines in the program has gone missing:

 

public static int[] revIntArray(int[] array) { int[] result = new int[array.length]; int index = array.length - 1;

for (int a : array) { result[index] = a;

// MISSING A LINE HERE

 

}

return result;

}

 

Which of the following lines should be inserted so that the method works correctly?

 

[A]     index++;

  • index-= 1;

  • a++;

[D]    a -= 1;

 Question 6 [2%]

 What output will be produced by the following Java program?

int[][] alpha = { {1, 2, 3 }, { 4, 5, 6 }};

int[] beta = alpha[0]; beta[1] = alpha[1][2];

System.out.println(alpha[0][1] + alpha[1][0]);

 

  • 6

  • 8

  • 10

  • 12

 

Question 7 [2%]

 Consider the following Java program

public class MainTest {

public static void main(String[] args) { if (args.length > 0)

System.out.println(main(args[0]));

}

public static String main() { return "Hello ";

}

public static String main(String x) { return main() + x;

}

}

 

Which of the following statements is true?

 

  • The program will not compile because you cannot have methods with the same name in one

  • When the program is run without a command line argument, it will throw a

StackOverflow exception.

  • When the program is run without a command line argument, it will exit without displaying a message or throwing an

  • When the program is run with the command line argument Jim, the console will display the message Hello Jim!

 Question 8 [2%]

 

Which of the following is NOT a java.util.Scanner method?

  • getNext

  • hasNext

  • next

  • nextDouble

Question 9 [2%]

 In the context of Java graphics programming, which of the following statements is true?

 

  • Class JComponent has a paintComponent method that can be overridden in subclasses.

  • The bottom-left corner of a window has coordinates (0,0) 

  • Class JFrame has a drawOval method for drawing an ellipse or circle.

  • The constructor invocation new JFrame("Hello World") will create a window with a content pane that shows the text "Hello World"

Question 10 [2%]

Which of the following statements about Java classes is false?

  • A class can have several

  • Classes can override the ==

  • Classes can override method toString 

  • Within a constructor, this is a reference to the current object which is being

Question 11 [2%]

 

Which of the following statements about Java access levels is false?

 

  • A private method can access a public field of another

  • A private method can only be accessed in its own class.

  • A method without explicit access level is visible from the same

  • A private data field can be read but not modified from outside the

 

Question 12 [2%]

 

Which interface does a Java class C need to implement in order for the method invocation

Arrays.sort(xs) to work properly where xs is an array of C elements?

 

  • Order 

  • Comparator 

  • Ordering 

  • Comparable 

Question 13

 

Consider the following statements about interfaces in Java:

  • All methods declared in an interface are automatically public

  • A class may implement at most one

  • Both statements are

  • The first statement is true; the second is

  • The first statement is false; the second is

  • Both statements are

Question 14 [2%]

 

Assume that List and ArrayList have been imported from package java.util

Which of the following statements does NOT compile?

 

  • List<Integer> a = new ArrayList<>(); 

  • List b = new ArrayList<Integer>(); 

  • ArrayList c = new ArrayList<Integer>(); 

  • ArrayList<Integer> d = new List<Integer>(); 

 

Question 15 [2%] 

Which of the following statements about Java class Object is false?

 

  • In the absence of any other explicit superclass, every class is implicitly a subclass of

Object 

  • Class Object has an equals method that compares objects for identity.

  • Class Object has a toString method that prints the name and value of all

  • Class Object is the only class which has no parent class.

Attachments:

Instructions Files

Java Programming Experts

expert
Neno S.
Java Programming

60 Answers

expert
Ray Bjork
Java Programming

90 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

250 Experts Online