IFT 210 Quiz Questions

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

Which of the following is an example of multiple inheritance? A computer can be a mainframe or a PC A PC can be a desktop or a laptop A laptop is both a PC and a portable device A portable device is a lightweight device Macintosh and IBM PC are both types of PCs

A laptop is both a PC and a portable device

To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do String names = {"Huey", "Duey", "Louie"}; String[ ] names = {"Huey", "Duey", "Louie"}; String[ ] names = new String{"Huey", "Duey", "Louie"}; String names[3] = {"Huey", "Duey", "Louie"}; String names; names[0] = "Huey"; names[1] = "Duey"; names[2] = "Louie";

String[ ] names = {"Huey", "Duey", "Louie"};

An array is stored in contiguous memory locations. You access the individual array value by using the array name followed by the index location. In other words, here is the array: 42 27 36 94 12 44 18 If you want to access the third value (36), you would use numbers[2] TRUE FALSE

TRUE

What happens if you declare a class constructor to have a void return type? The class' default constructor will be used instead of the one you're declaring. The program will compile with a warning, but you'll get a runtime error There's nothing wrong with declaring a constructor to be void Your computer will crash and your CPU will burst into flames! Everyone knows that you cannot put a return type on a constructor, not even 'void'! None of the above

The class' default constructor will be used instead of the one you're declaring.

In order to determine the type that a polymorphic variable refers to, the decision is made by the programmer at the time the program is written by the compiler at compile time by the operating system when the program is loaded into memory by the Java run-time environment at run time by the user at run time

by the Java run-time environment at run time

A unique aspect of Java that allows code compiled on one machine to be executed on a machine of a different hardware platform is Java's bytecodes syntax use of objects use of exception handling all of the above

bytecodes

The instruction super( ); does which of the following? calls the method super as defined in the current class calls the method super as defined in the current class'parent class calls the method super as defined in java.lang calls the constructor as defined in the current class calls the constructor as defined in the current class' parent class

calls the constructor as defined in the current class'parent class

If x is a char, and values is an int array, then values[x] causes a syntax error causes an Exception to be thrown casts x as an int based on x's position in the alphabet (for instance, if x is 'a' then it uses 0 and if x is 'z' then it uses 25) casts x as an int based on x's ASCII value (for instance, if x is 'a' then it uses 97 and if x is 'z' then it uses 122) x as an int based on the digit that is stored in x (for instance, if x is '3' it uses 3) but throws an exception if x does not store a digit

casts x as an int based on x's ASCII value (for instance, if x is 'a' then it uses 97 and if x is 'z' then it uses 122)

Assume values is an int array that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 The statement System.out.println(values[7]); will output 7 output 18 output nothing cause an ArrayOutOfBoundsException to be thrown cause a syntax error

cause an ArrayOutOfBoundsException to be thrown

If a programmer writes a class wanting it to be extended by another programmer, then this programmer should change private methods and instance data to be protected change public methods and instance data to be protected change all methods to be protected change the class to be protected none of the above, the programmer should not change anything

change private methods and instance data to be protected

Inheritance through an extended (derived) class supports which of the following concepts? interfaces modulary information hiding code reuse correctness

code reuse

If a and b are both int arrays, then a = b; will create an alias copy all elements of b into a copy the 0th element of b into the 0th element of a return true if each corresponding element of b is equal to each corresponding element of a (that is, a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise return true if a and b are aliases and return false otherwise

create an alias

A Java variable is the name of a: numeric data value stored in memory data value stored in memory that can not change during the program's execution data value stored in memory that can change its value but cannot change its type during the program's execution data value stored in memory that can change both its value and its type during the program's execution data value or a class stored in memory that can change both its value and its type during the program's execution

data value stored in memory that can change its value but cannot change its type during the program's execution

Using getCurrencyInstance( ) formats a variable, automatically inserting decimal point for cents dollar sign percent sign all three A and B but not C

decimal point for cents and dollar sign

The line of Java code "// System.out.println("Hello");" will do nothing cause "Hello" to be output cause a syntax error cause "(Hello)" to be output there is no way to know without executing this line of code

do nothing

What are the main programming mechanisms that constitute object-oriented programming? encapsulation, inheritance, polymorphism encapsulation, abstraction, inheritance inheritance, polymorphism, recursion polymorphism, recursion, abstraction none of the above

encapsulation, inheritance, polymorphism

An example of passing message to a String where the message has a String parameter would occur in which of the following messages? length substring equals toUpperCase none of the above, it is not possible to pass a String as a parameter in a message to a String

equals

Java methods can return more than one item if they are modified with the reserved word continue, as in public continue int foo( ) { ... } true false

false

Assume values is an int array that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 Which of the following loops would adequately add 1 to each element stored in values? for (j=1; j<values.length; j++) values[j]++; for (j=0; j<values.length; j++) values[j]++; for (j=0; j<=values.length; j++) values[j]++; for (j=0; j<values.length-1; j++) values[j]++;

for (j=0; j<values.length; j++) values[j]++;

Which of the following is a legal Java identifier? i class ilikeclass! idon'tlikeclass i-like-class

i

Copy of Of the following if statements, which one correctly executes three instructions if the condition is true? if (x < 0) a = b * 2; y = x; z = a - y; { if (x < 0) a = b * 2; y = x; z = a - y; } if { (x < 0) a = b * 2; y = x; z = a - y ; } if (x < 0) { a = b * 2; y = x; z = a - y; }

if (x < 0) { a = b * 2; y = x; z = a - y; }

Of the following if statements, which one correctly executes three instructions if the condition is true? if (x < 0) a = b * 2; y = x; z = a - y; { if (x < 0) a = b * 2; y = x; z = a - y; } if { (x < 0) a = b * 2; y = x; z = a - y ; } if (x < 0) { a = b * 2; y = x; z = a - y; }

if (x < 0) { a = b * 2; y = x; z = a - y; }

Which of the sets of statements below will add 1 to x if x is positive and subtract 1 from x if x is negative but leave x alone if x is 0? if (x > 0) x++; else x--; if (x > 0) x++; else if (x < 0) x--; if (x > 0) x++; if (x < 0) x--; else x = 0; if (x == 0) x = 0; else x++; x--; E) x++; x--;

if (x > 0) x++; else if (x < 0) x--;

The statement int[ ] list = {5, 10, 15, 20}; adds 4 int values to array list initializes list to have 20 int values initializes list to have 4 int values declares list but does not initialize it causes a syntax error because it does not include "new int[4]" prior to the list of values

initializes list to have 4 int values

The relationship between a parent class and a child class is referred to as a(n) ________ relationship. has-a is-a was-a instance-of alias

is-a

If a method does not have a return statement, then it will produce a syntax error when compiled it must be a void method it can not be called from outside the class that defined the method it must be defined to be a public method it must be an int, double, float or String method

it must be a void method

Which library package would you import to use the class Random? java.beans java.io java.lang java.text java.util

java.util

Instance data for a Java class are limited to primitive types (e.g., int, float, char) are limited to Strings are limited to objects(e.g., Strings, classes defined by other programmers) may be primitive types or objects, but objects must be defined to be private may be primitive types or objects

may be primitive types or objects

The behavior of an object is defined by the object's instance data constructor visibility modifiers methods all of the above

methods

Which of the following reserved words in Java is used to create an instance of a class? class public public or private, either could be used import new

new

The relationship between a class and an object is best described as classes are instances of objects objects are instances of classes objects and classes are the same thing classes are programs while objects are variables objects are the instance data of classes

objects are instances of classes

Which of the following is a legal Java identifier? 1ForAll oneForAll one/4/all 1_4_all 1forall

oneForAll

Polymorphism is achieved by overloading overriding embedding abstraction encapsulation

overriding

A variable declared to be of one class can later reference an extended class of that class. This variable is known as protected derivable cloneable polymorphic none of the above, a variable declared to be of one class can never reference any other type of class, even an extended class

polymorphic

To define a class that will represent a car, which of the following definitions is most appropriate? private class car public class car public class Car public class CAR private class Car

public class Car

The main method for a Java program is defined by public static void main( ) public static void main(String[ ] args); public static void main(String[ ] args) private static void main(String[ ] args) the main method could be defined as in A, C or D but not B

public static void main(String[ ] args)

Visibility modifiers include public, private public, private, protected public, private, protected, final public, protected, final, static public, private, protected, static

public, private, protected

The do loop differs from the while loop in that: the while loop will always execute the body of the loop at least once the do loop will always execute the body of the loop at least once the do loop will continue to loop while condition in the while statement is false and the while loop will continue to loop while the condition in the while statement is true the while loop will continue to loop while condition in the while statement is false and the do loop will continue to loop while the condition in the while statement is true none of the above, there is absolutely no difference between the two types of loops

the do loop will always execute the body of the loop at least once

When comparing any primitive type of variable, == should always be used to test to see if two values are equal. True False

true

Consider the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following lists of instance data are accessible in class A2? x, y, z, a, b x, y, z, a x, z, a, b z, a, b a,

x, z, a, b

Consider the following partial class definitions: public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } Which of the following lists of instance data are accessible in A3? x, y, z, a, b, q a, b, q a, q x, z, a, q x, a, q

x, z, a, q

What value will z have if we execute the following assignment statement?float z = 5 / 10; z will equal 0.0 z will equal 0.5 z will equal 5.0 z will equal 0.05 none of the above; a run-time error arises because z is a float and 5 / 10 is an int

z will equal 0.0

A switch statement must have a default clause. True False

False

Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header. True False

False

In Java, it is possible to create an infinite loop out of while and do loops, but not for-loops. True False

False

In Java, selection statements consist of the if and if-else statements. True False

False

In Java, the symbol "=" and the symbol "==" are used synonymously (interchangeably). True False

False

In a Java program, dividing by 0 is a syntax error. True False

False

In order to compare int, float and double variables, you can use <, >, ==, !=, <=, >=, but to compare char and String variables, you must use compareTo( ), equals( ) and equalsIgnoreCase( ). True False

False

Java arrays can store primitive types and Strings, but cannot store any other type of Object other than Strings. True False

False

Java byte codes are directly executable whereas Java source code is not. True False

False

Java methods can return only primitive types (int, double, float, char, boolean, etc). True False

False

System.out.print is used in a program to denote that a documentation comment follows. True False

False

The following loop is syntactically valid. for (int j = 0; j < 1000; j++) j--;

False

The reserved word, extends, is used to denote a has-a relationship. True False

False

The values of (double) 5 / 2 and (double) (5 / 2) are identical.

False

The word "Public" is a reserved word. True False

False

To swap the 3rd and 4th elements in the int array values, you would do: values[3] = values[4]; values[4] = values[3]; True False

False

Which of the following is true regarding the mod operator, %? It can only be performed on int values and its result is a double It can only be performed on int values and its result is an int It can only be performed on float or double values and its result is an int It can only be performed on float or double values and its result is a double It can be performed on any numeric values, and the result always is numeric

It can be performed on any numeric values, and the result always is numeric

What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0. for (int j = 0; j < list.length; j++) if (list[j] < temp) c++; It finds the smallest value and stores it in temp It finds the largest value and stores it in temp It counts the number of elements equal to the smallest value in list It counts the number of elements in list that are less than temp

It counts the number of elements in list that are less than temp

The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values only. int foo = 0; for (int j =0 ; j < list.length; j++) if (list[j] > foo) foo = list[j]; It stores the smallest value in list (the minimum) in foo It stores the largest value in list (the maximum) in foo It stores every value in list, one at a time, in foo, until the loop terminates It counts the number of elements in list that are greater than foo

It stores the largest value in list (the maximum) in foo

In order to preserve encapsulation of an object, we would do all of the following except for which one? Make the instance data private Define the methods in the class to access and manipulate the instance data Make the methods of the class public Make the class final All of the above preserve encapsulation

Make the class final

Consider the class definition below. import java.text.DecimalFormat; public class Student { private String name; private String major; private double gpa; private int hours; public Student(String newName, String newMajor, double newGPA, int newHours) { name = newName; major = newMajor; gpa = newGPA; hours = newHours; } public String toString( ) { DecimalFormat df = new DecimalFormat("xxxx"); // xxxx needs to be replaced return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } Which of the following patterns should be used in place of "xxxx" when instantiating df so that the gpa to be output in typical form (like 3.810)? "#.###" "#.0" "0.# " "0.000" "0.0##"

"0.000"

For the program below, the final println command will output public class Questions1_4 { public static void main(String[ ] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } "But not in Texas" "But notin Texas" "But not" on one line and "in Texas" on the next line "But not+in Texas" "But not + in Texas"

"But notin Texas"

If the String major = "Computer Science", what is returned by major.charAt(1)? 'C' Correct! 'o' 'm' "C" "Computer"

'o'

The instruction: System.out.println("Hello World"); might best be commented as // prints "Hello World" to the screen // prints a message // used to demonstrate an output message // // meaningless instruction

// used to demonstrate an output message

If you want to output a double so that at least 1 digit appears to the left side of the decimal point and exactly 1 digit appears to the right side of the decimal point, which pattern would you give a DecimalFormat variable when you instantiate it? "0.0" "0.#" "0.0#" "0.##" "#.#"

0.0

How many times will the following loop iterate? int x = 10; while (x > 0) { System.out.println(x); x--; } 0 times 1 time 9 times 10 times

10 times

How many lines of output are provided by this program? public class Questions1_4 { public static void main(String[ ] args) { System.out.print("Here"); System.out.println("There " + "Everywhere"); System.out.println("But not" + "in Texas"); } } 1 2 3 4 5

2

A color image is broken down into individual pixels (points), each of which is represented by a 1 for white and a 0 for black 3 values denoting the intensity of red, green, and blue in the image a single number indicating the intensity of color between white and black two numbers, a value that denotes where between white and black the color is, and a brightness none of the above, it is not possible to represent a color image

3 values denoting the intensity of red, green, and blue in the image

Assume values is an int array that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 What is the value of values.length? 0 5 6 7 18

7

Which of the following characters does not need to have an associated "closing" character in a Java program? { ( [ < all of these require closing characters

<

Which of the following is true regarding Java classes? All classes must have 1 parent but may have any number of children (derived or extended) classes All classes must have 1 child (derived or extended) class but may have any number of parent classes All classes must have 1 parent class and may have a single child (derived or extended) class All classes can have any number (0 or more) of parent classes and any number of children (derived or extended) classes All classes can have either 0 or 1 parent class and any number of children (derived or extended) classes

All classes must have 1 parent but may have any number of children (derived or extended) classes

What is wrong, logically, with the following code? if (x > 10) System.out.println("Large"); else if (x > 6 && x <= 10) System.out.println("Medium"); else if (x > 3 && x <= 6) System.out.println("Small"); else System.out.println("Very small"); There is no logical error, but there is no need to have (x <= 10) in the second conditional or (x <= 6) in the third conditional There is no logical error, but there is no need to have (x > 6) in the second conditional or (x > 3) in the third conditional The logical error is that no matter what value x is, "Very small" is always printed out The logical error is that no matter what value x is, "Large" is always printed out

There is no logical error, but there is no need to have (x <= 10) in the second conditional or (x <= 6) in the third conditional

A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply "command-line" parameters. Since the parameter is a String array, however, the user does not have to supply any parameters. True False

True

A constructor may contain a return statement so long as no value (or expression) is returned.

True

A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables. true False

True

An array index cannot be a float, double, boolean or String. True False

True

Consider the following class hierarchy and answer these questions. X > Y & Z Y> A & B If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B. True False

True

Consider the following class hierarchy and answer these questions. x > Y & Z Y > A & B A is a derived class of Y. True False

True

Control in a switch statement jumps to the first matching case. True False

True

Defining formal parameters requires including each parameters type. True False

True

If String a = "ABCD" and String b = "abcd" then a.equals(b); returns false but a.equalsIgnoreCase(b); returns true.

True

If x is a string, then x = new String("OH"); and x = "OH"; will accomplish the same thing.

True

In Java, 'a' and 'A' are considered to be different values.

True

In Java, an array can only store one type of data. For instance, you cannot create an array that stores both double and String values. True False

True

In order to generate a random number, you must use Math.random( ).

True

The following for-loop is an infinite loop. for (int j = 0; j < 1000; ) i++; True False

True

The following method header definition will result in a syntax error: public void aMethod( ); True False

True

The protected visibility modifier provides the best possible encapsulation that permits inheritance. True False

True

The statement { } is a legal block. True False

True

There are three ways that data conversion may occur: by assignment, by promotion, by casting.

True

Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length(), in order to use the Math classes, you pass messages directly to the class name, as in Math.abs().

True

While multiple objects of the same class can exist, in a given program there can be only one version of each class. True False

True

Which character below is not allowed in an identifier? $ _ 0 (zero) q ^

^

Which of the following is true regarding Java syntax and semantics? a Java compiler can determine if you have followed proper syntax but not proper semantics a Java compiler can determine if you have followed proper semantics but not proper syntax a Java compiler can determine if you have followed both proper syntax and semantics a Java compiler cannot determine if you have followed either proper syntax or semantics a Java compiler can determine if you have followed proper syntax and can determine if you have followed proper semantics if you follow the Java naming convention rules

a Java compiler can determine if you have followed proper syntax but not proper semantics

An error in a program that results in the program outputting $100 instead of the correct answer, $250 is a programmer error a syntax error a run-time error a logical error a snafu

a logical error

Mistyping "println" as "printn" will result in a syntax error a run-time error a logical error no error at all converting the statement into a comment

a syntax error

Given the following declarations, which of the following variables are arrays? int[ ] a; int b[ ]; int c<>; int d[ ]; a a and b a and d a, b and d c only

a, b and d

The expressions that are passed to a method in an invocation are called actual parameters formal parameters formal arguments formals any of the above

actual parameters


Ensembles d'études connexes

MCCC PSY 101 FINAL EXAM WINTER 2020

View Set

Joint Play Assignment Q's MHVicars

View Set

Chapter 13 The cost of production

View Set

THE MUSCULAR SYSTEM EXAM STUDY GUIDE

View Set