logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

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?

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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.

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

845 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

625 Answers

Hire Me
expert
Husnain SaeedComputer science

641 Answers

Hire Me
expert
Atharva PatilComputer science

946 Answers

Hire Me

Get Free Quote!

362 Experts Online