COP 2800 Java 1: Review Quiz Correct Answers

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Module 3: ________ refers to the number of parameters a method accepts. Arity Variability Parameterizability Size

Arity

Module 1: Java borrows heavily from ______. Python C++ C C#

C++

Module 2: What is the literal value of '\u0045' ? U 5 E %

E

Module 6: True or False: element values in an enhanced for loop body can be changed. True False

False

Module 1: Java SE8 refers to ________. Java Standard Enterprise 8 Java Standard Edition 8 Java Select Enterprise 8 Java Select Edition 8

Java Standard Edition 8

Module 1: Java bytecode is executed by the ________. Java Virtual Machine Java Interpreter Java Compiler Java Executor

Java Virtual Machine

Module 2: The _______ suffix forces a literal to a long value. D F 0x L

L

Module 4: Given the Java file shown below, what would the file be named? public class MyClass { } class ClassA { } class ClassB { } MyClassAB.java MyClass.java MyClass.txt My_Class.java

MyClass.java

Module 4: ________ methods are implemented in a language other than Java . Automatic Native Remote Compiled

Native

Module 5: True or False: The unary + (addition) operator has a higher precedence than the binary * (multiplication) operator. True False

True

Module 6: True or False: Switch statements can be nested. True False

True

Module 5: What will be displayed when the following code snippet is executed? String s = "Welcome "; s += "to "; String s1 = s + "Java Chapter " + 2 + 2; System.out.println(s1); Welcome to Java Welcome to Java Chapter 4 Welcome to Welcome to Java Chapter 22

Welcome to Java Chapter 22

Module 3: A method declaration includes a return type, method name, and ________. return statement semi-colon a parameter list body braces

a parameter list

Module 4: A subclass in another package can only access protected members in its superclass using ________. a reference to its own type a static reference a reference to its subtype a fully-qualified name

a reference to its own type

Module 4: A(n) ________ method in a super (parent) enforces behavior among its sub (child) classes. abstract concrete extended inherited

abstract

Module 1: A(n) ________ is a "useful object" for which we do not need to know the internal details. abstraction reference alias property

abstraction

Module 1: Multiple references which refer to the same object are known as ________. relatives aliases duplicates common objects

aliases

Module 7: Private, overridden, and hidden members of a superclass ________ inherited by a subclass. are not are

are not

Module 2: Underscores in Java numeric literals must be inserted ________ the digits. before between after

between

Module 3: Which one of the choices shown below is the signature for the following method declaration: public String build(String s1, String s2, Object o1, Object o2, int i1, int i2, double d) build(s1, s2, o1, o2, i1, i2, d) String build(String s1, String s2, Object o1, Object o2, int i1, int i2, double d) build(String, String, Object, Object, int, int, double) String build(String, String, Object, Object, int, int, double)

build(String, String, Object, Object, int, int, double)

Module 3: In Java, all parameters are passed ________. in sequential order by value by reference in alphabetical order

by value

Module 1: Compiled Java source code is known as ________. object code compiled code bytecode bitcode

bytecode

Module 5: Suppose x is a char variable with the value 'b'. What is the output of the statement System.out.println(++x)? b 99 a c

c

Module 2: Identify the primitive data types from the declarations provided. Select the three correct answers. String name; char firstInitial; double taxRate; int count;

char firstInitial; double taxRate; int count;

Module 2: Match the data type with its default initial value. char float long reference type boolean byte

char: '\u0000\ float: 0.0F long: 0L reference type: null boolean: false byte: 0

Module 1: The main method of a Java program is always enclosed in a ________. package folder method class

class

Module 4: Static methods are known as ________ methods. class instance anonymous global

class

Module 2: Identify the reference types from the choices provided. Select the two correct answers. class int interface boolean

class interface

Module 1: Users of a Java class are known as ________. testers developers clients customers

clients

Module 4: You are writing a Java widget toolkit for the WidgetCo company (home page: www.widgetco.com). Your classes represent steel widgets of various types and brass widgets of various types. Which of the choices shown below would best represent the fully qualified package names of the Java packages that will contain your classes? Select the two correct answers. com.widgetco.widget.steel widgetco.com.widget.brass widgetco.widget.steel widgetco.com.widget.steel com.widgetco.widget.brass widgetco.widget.brass

com.widgetco.widget.steel com.widgetco.widget.brass

Module 3: The String array parameter declared in the main method in a Java class receives and stores ________. the available memory size operating system parameters command-line parameters the monitor resolution

command-line parameters

Module 3: Which of the following can a Java class body contain? Select the three correct answers constructor declarations import statements global variables field declarations method declarations

constructor declarations field declarations method declarations

Module 1: A ________ specifies what services are provided by a class. menu contract commitment agreement

contract

Module 3: Which of the following is the correct way to reference the length of an array named counters? counters.size() counters.length counters.size counters.length()

counters.length

Module 4: Which of the following choices are valid top-level type accessibility modifiers? Select the two correct answers. default (no modifier) private public protected

default (no modifier) public

Module 1: Which of the following is not a Java comment style? line block descriptive javadoc

descriptive

Module 2: ________ is the default floating point literal type. float short double long

double

Module 3: Which one of the following choices is the correct way to declare and initialize an array of type double of size 3? double[3] temp = { 59.0, 73.5, 82.1 }; double temp[3] = { 59.0, 73.5, 82.1 }; double temp[] = { 59.0, 73.5, 82.1 }; double temp[] = new { 59.0, 73.5, 82.1 };

double temp[] = { 59.0, 73.5, 82.1 };

Module 5: What is the output of the following code? boolean even = false; System.out.println((even ? "true" : "false")); false true true false false true no output

false

Module 1: Properties are defined by ________ in Java, and behaviors are defined by ________. fields, methods methods, fields classes, methods methods, variables

fields, methods

Module 4: Declare a class as ________ to prevent inheritance. abstract final private static

final

Module 6: The ________ clause is always executed regardless of whether an exception is caught or not. finally end catch default

finally

Module 6: Which of the following is the correct declaration of a FOR loop which will iterate 5 times, assuming an integer variable named 'i'? for (i = 1; i == 5; i++) System.out.println("i = " + i); for (i = 0; i < 5; i++) System.out.println("i = " + i); for (i = 0; i <= 5; i++) System.out.println("i = " + i); for (i = 0; i > 5; i++); System.out.println("i = " + i);

for (i = 0; i < 5; i++) System.out.println("i = " + i); (Correct. Looping from 0 to 4 ("&lt; 5") will iterate 5 times.)

Module 2: A name in a Java program is known as a(n) ________. identifier literal variable keyword

identifier

Module 4: Given the following fully qualified class names jet.fuselage.wings.RightWing jet.fuselage.wings.LeftWing jet.fuselage.wings.flaps.RightWingOuterFlap jet.fuselage.wings.flaps.LeftWingOuterFlap Which of the following blocks of import statements will correctly allow the use of the simple names RightWing and RightWingOuterFlap? Select the three correct answers. import jet.fuselage.wings.*; import jet.fuselage.wings.flaps.RightWingOuterFlap; import jet.fuselage.*; import jet.fuselage.wings.flaps.*; import jet.fuselage.*; import jet.fuselage.wings.*; import jet.fuselage.wings.RightWing; import jet.fuselage.wings.flaps.*; import jet.fuselage.wings.*; import jet.fuselage.wings.flaps.*; import jet.*; import jet.fuselage.wings.*;

import jet.fuselage.wings.*; import jet.fuselage.wings.flaps.RightWingOuterFlap; import jet.fuselage.wings.RightWing; import jet.fuselage.wings.flaps.*; import jet.fuselage.wings.*; import jet.fuselage.wings.flaps.*;

Module 1: An object is a(n) ________ of a class. realization instance example implementation

instance

Module 2: Match the category of variable with its scope. instance static local

instance: associated object exists static: class is loaded local: method / constructor is executing

Module 5: Which one of the following operators is used to test the type of an object? instanceof type istype typeof

instanceof

Module 2: A(n) ________ data type is a 4-byte (32-bit) signed integer value. Textbox

int

Module 3: Which one of the following choices is not a block? { } int[] scores = { 10, 10, 15 }; {int x = 2; System.out.println(Math.sqrt(x));} {System.out.println("Hello, World");}

int[] scores = { 10, 10, 15 };

Module 7: A subclass which inherits from a superclass implements a(n) ________ relationship. part-of is-a has-a like-a

is-a

Module 4: Given the class XYZ in the package a.b.c, which one of the following choices is the correct way to execute the main method in the XYZ class? java a.b.c.XYZ.main java XYZ java a.b.c.XYZ java a.b.c.XYZ.class

java a.b.c.XYZ

Module 7: All Java classes inherit from ________. java.lang.Class java.lang.Object java.util.Object java.util.Class

java.lang.Object

Module 2: A ________ denotes a constant value. keyword variable identifier literal

literal

Module 2: ________ variables must be explicitly initialized. hidden local static instance

local

Module 3: Parameters are ________ in scope to the method where they are declared. global associated local related

local

Module 2: All Java keywords are spelled in ________. ASCII unicode sentence case lower case

lower case

Module 4: static final members are frequently used to represent ________ constants. temporary common manifest anonymous

manifest

Module 1: Java provides ________, which allows for the performance of different tasks concurrently in an application. interprocess communication synchronization multithreading multitasking

multithreading

Module 5: The _______ operator is used to create objects, including instances of classes and arrays new assignment creation instantiation

new

Module 7: An ________ requires a matching method signature, the return type does not matter overload override

overload

Module 7: An ________ requires a matching method signature and a matching or covariant return type. overload override

override

Module 3: Class names should be spelled using ________ case by convention. camel pascal lower upper

pascal

Module 1: Select the three properties of object-oriented languages from the choices shown below. serialization polymorphism dynamic typing procedural execution inheritance encapsulation

polymorphism inheritance encapsulation

Module 4: A standard design strategy for classes is to make all instance variables ________ and provide ________ accessor and mutator methods for them. public, public private, private private, public public, private

private, public

Module 4: Select the valid local variable declarations from the choices shown below. Select the three correct answers. *not this answer* public class LocalScope { public static void main(String args[]) { int x = 5; { int x = 10; } } }

public class LocalScope { public static void main(String args[]) { int x = 5; { int y = 10; } } } public class LocalScope { public static void main(String args[]) { { int x = 5; } { int x = 10; } } } public class LocalScope { public static void main(String args[]) { { int x = 10; } int x = 5; } }

Module 1:The main method in a Java program must be declared as ________. public static void void public static public

public static void

Module 3: The following array declaration creates a(n) ________ array. int[][] tArray = { { 1, 2, 3 }, { 1, 2 }, { 1 } }; incremental ragged rectangular offset

ragged

Module 3: A class declaration introduces a new ________. identifier reference type variable keyword

reference type

Module 1: A ________ is returned when an object is instantiated. reference value data type string class

reference value

Module 2: The ________ of a variable depends on the context in which it is declared. instantiation value scope size

scope

Module 2: The ________ data type is the smallest Java integer type that can be used to store the value 30000. int byte long short

short

Module 3: How would you reference the last element in the following multi-dimensional array? int square[][] = new int[3][2]; square[3][2] square[3][3] square[2][1] square[2][2]

square[2][1]

Module 6: The ______ is a data structure which contains frames representing active methods in a Java program. When a method is called, a frame is pushed onto this data structure; when the method returns, the frame is popped from the data structure. cache stack heap array storage region

stack

Module 1: Java is a ________ typed language. randomly statically dynamically numerically

statically

Module 4: The _________ keyword specifies that only one thread can access a shared object at a time. transient locked exclusive synchronized

synchronized

Module 2: A ________ is a basic language element. atom token abstraction word

token

Module 4: The ________ modifier specifies that a field cannot be serialized. transient volatile automatic private

transient

Module 2: Identify the reserved keywords from the choices shown below. Select the three correct answers. until transient assert catch before

transient assert catch

Module 4: The ________ modifier can be used to inform the compiler that it should not attempt to optimize a field. transient static isolate volatile

volatile

Module 7: Assigning a subclass reference to a superclass reference is a ________ reference conversion. static narrowing widening dynamic

widening

Module 3: Which one of the following choices is not a valid expression statement? ; x = y + z sum(val1, val2); Pizza pizza = new Pizza();

x = y + z

Module 1: Select the best choice to fill in the following blank: A Java class may contain ________ main method(s). one zero zero or one more than one

zero or one

Module 3: How many elements are in the following array? char vowels[] = { 'a', 'e', 'i', 'o', 'u' }; 6 0 4 5

5

Module 2: The Unicode value for the letter P is '\u0050' , which is equivalent to decimal 80. Given this information, what is the decimal ASCII value for the letter P? 16 112 80 50

80

Module 7: Which of the following statements about overriding is true? The return type of an override must match the return type of the superclass method. An override can throw all, none, or a subset of the checked exceptions specified in the throws clause of the superclass method An override must have the same method signature as the superclass method. An override cannot widen the accessibility of the superclass method.

An override can throw all, none, or a subset of the checked exceptions specified in the throws clause of the superclass method An override must have the same method signature as the superclass method.

Module 2: Identify the whitespace character literals from the choices shown below. Select the three correct answers. ';' '\\' ' ' '\n' '\t' '@'

' ' '\n' '\t'

Module 5: Identify the expressions that will evaluate to true, given the following assigned values for variables a, b, and c. Identify the four correct answers. int a = 20; int b = 25; int c = 30; ((a < b) || (b < c)) ((a < b) || (b > c)) ((a > b) || (b < c)) ((a < b) && (b > c)) ((a > b) && (b < c)) ((a < b) && (b < c))

((a < b) || (b < c)) ((a < b) || (b > c)) ((a > b) || (b < c)) ((a < b) && (b < c))

Module 5: Which one of the following expressions evaluates to true if the number x is between 1 and 100 or x is negative? ((x < 100) && (x > 1)) || (x < 0) 1 < x < 100 && x < 0 (1 > x > 100) || (x < 0) ((x < 100) && (x > 1)) && (x < 0)

((x < 100) && (x > 1)) || (x < 0)

Module 4: Match the UML prefix with the corresponding accessibility modifier (some prefixes have no match). + # - (no prefix)

+: public #: protected -: private (no prefix): default

Module 5: Identify the operator with the lowest precedence from the choices shown below. / += * %

+=

Module 6: What is y after the following switch statement is executed? int x = 3, y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; } 0 1 4 3 2

2 (Correct. Since x is 3, x + 3 is 6. So, case 6 is executed.Since there is no break statement, the statement in the next case is executed. y is now 1. Finally y += 1 adds 1 to y.So y is 2.)

Module 3: For the array declared below, choose the correct value for list[1]. double[] list = { 3.4, 2.0, 3.5, 5.5 } 3.4 2.0 5.5 3.5

2.0

Module 5: What is y after the following statement is executed? x = 0; y = (x > 0) ? 10 : - 10; -10 0 20 10

-10

Module 4: What java command option is used to individually set the class path for an application? -classpath -path -class:path -class

-classpath

Module 2: Match the comment characters with the description. // /* */ /** */ #

//: single-line /* */: multiple-line /** */: documentation #: not a Java comment character

Module 4: A maximum of ________ accessibility modifiers can be applied to a class member. 2 3 1 4

1

Module 4: How many package declarations can a Java source file contain? 0 1 2 3 or more

1

Module 1: Which one of the following statements will produce the output shown here, based on the variable values provided? int count = 5; double costPerItem = 4.99; String itemType = "grocery"; System.out.printf(________); Output: Total cost for 5 grocery items: $24.95 System.out.printf("Total cost for %.2f %s items: $%d",count, itemType, count * costPerItem); System.out.printf("Total cost for %d %s items: $%5.2f", itemType, count, count * costPerItem); System.out.printf("Total cost for %d %s items: $%5.2f", count, itemType, count * costPerItem); System.out.printf("Total cost for %s %d items: $%5.2f", count, itemType, count * costPerItem);

System.out.printf("Total cost for %d %s items: $%5.2f", count, itemType, count * costPerItem);

Module 1: The ________ method displays output to the console in a Java program. System.println System.out.println println System.out.display

System.out.println


Ensembles d'études connexes

health and nutrition: lacto-ovo-vegetarian diet

View Set

Ch. 10 Adaptive Quiz: Introduction to Organic Chemistry: Hydrocarbon Structure

View Set

ANA Scope and Standards of Practice

View Set

Chapter 68: Emergency and Disaster Nursing Lewis: Medical-Surgical Nursing, 10th Edition ?'s

View Set