logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

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

expert
Venktesh PrasaadMarketing
(5/5)

618 Answers

Hire Me
expert
StatAnalytica ExpertSociology
(5/5)

586 Answers

Hire Me
expert
Nathaniel KellyComputer science
(5/5)

650 Answers

Hire Me
expert
Paul BurlinggComputer science
(5/5)

500 Answers

Hire Me
Java Programming

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.

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. 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

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme