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

678 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

758 Answers

Hire Me
expert
Husnain SaeedComputer science

631 Answers

Hire Me
expert
Atharva PatilComputer science

510 Answers

Hire Me
March
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30