JAVA test 1 – Flashcards

Unlock all answers in this set

Unlock answers
question
A Java program is best classified as
answer
software
question
6 bits can be used to represent ________ distinct items or
answer
64
question
When executing a program, the processor reads each program instruction from
answer
main memory
question
Which memory capacity is the largest?
answer
12,000,000 megabytes
question
Binary numbers are composed entirely of
answer
0s and 1s
question
Volatility is a property of
answer
RAM
question
The ability to directly obtain a stored item by referencing its address is known as
answer
random access
question
Which phase of the fetch-decode-execute cycle might use a circuit in the arithmetic-logic unit?
answer
execute
question
In order for a computer to be accessible over a computer network, the computer needs its own
answer
network address
question
For a computer to communicate over the Internet, it must use
answer
the combined TCP/IP protocol
question
A URL (Universal Resource Locator) specifies the address of
answer
a document or other type of file on the Internet
question
It is important to dissect a problem into manageable pieces before trying to solve the problem because
answer
most problems are too complex to be solved as a single, large activity
question
Once we have implemented the solution, we are not done with the problem because
answer
1) the solution may not be the best (most efficient) 2) the solution may have errors and need testing and fixing before we are done 3)the solution may, at a later date, need revising to handle new specifications 4) the solution may, at a later date, need revising because of new programming language features
question
Java is an example of
answer
both high-level language and fourth generation language
question
In the following list, which statement is not true regarding Java as a programming language? 1) It is a relatively recent language, having been introduced in 1995 2) It is a language whose programs do not require translating into machine language before they are executed 3) It is an object-oriented programming language 4) It is a language that embraces the idea of writing programs to be executed using the World Wide Web 5) all of these are true
answer
It is a language whose programs do not require translating into machine language before they are executed
question
Comments should
answer
be insightful and explain what the instruction's intention is
question
The main method for a Java program is defined by
answer
public static main(String[ ] args)
question
The line of Java code "// System.out.println("Hello");" will
answer
do nothing
question
The instruction: System.out.println("Hello World"); might best be commented as
answer
// used to demonstrate an output message
question
Which character below is not allowed in an identifier? 1) $ 2) _ 3) 0 (zero) 4) q 5) ^
answer
^
question
Which of the following is not syntactically legal in Java? 1) public class Foo 2) System.out.println("Hi"); 3) { } 4) s t a t i c main(String[ ] args) 5) only System.out.println("Hi"); is legally valid, all of the rest are illegal
answer
4) s t a t i c main(String[ ] args)
question
Which of the following is a legal Java identifier? 1) i 2) class 3) ilikeclass! 4) idon'tlikeclass 5) i-like-class
answer
i
question
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
answer
bytecodes
question
Java is similar in syntax to what other high level language?
answer
C++
question
An error in a program that results in the program outputting $100 instead of the correct answer, $250 is
answer
a logical error
question
Which of the following is true regarding Java syntax and semantics? 1) a Java compiler can determine if you have followed proper syntax but not proper semantics 2) a Java compiler can determine if you have followed proper semantics but not proper syntax 3) a Java compiler can determine if you have followed both proper syntax and semantics 4) a Java compiler cannot determine if you have followed either proper syntax or semantics 5) 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
answer
a Java compiler can determine if you have followed proper syntax but not proper semantics
question
Following Java naming convention, which of the following would be the best name for a class about store customers? 1) StoreCustomer 2) Store Customer 3) storeCustomer 4) STORE_CUSTOMER 5) Store-Customer
answer
StoreCustomer
question
Which of the following would be a good variable name for the current value of a stock? 1) curstoval 2) theCurrentValueOfThisStockIs 3) currentStockVal 4) csv 5) current
answer
currentStockVal
question
Which of the following is a legal Java identifier? 1) 1ForAll 2) oneForAll 3) one/4/all 4) 1_4_all 5) 1forall
answer
oneForAll
question
A color image is broken down into individual pixels (points), each of which is represented by
answer
3 values denoting the intensity of red, green, and blue in the image
question
Which of the following characters does not need to have an associated "closing" character in a Java program? 1) { 2) ( 3) [ 4) ; 5) all of these require closing characters
answer
;
question
Mistyping "println" as "printn" will result in
answer
a syntax error
question
________ is the physical aspect of the computer that can be seen.
answer
Hardware
question
________ is the brain of a computer.
answer
CPU
question
The speed of the CPU is measured in ________.
answer
megahertz gigahertz
question
Why do computers use zeros and ones?
answer
because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
question
One byte has ________ bits.
answer
8
question
Which of the following are storage devices? (Choose all that apply.) 1) floppy disk 2) hard disk 3) flash stick 4) CD-ROM
answer
floppy disk hard disk flash stick
question
________ is a device to connect a computer to a local area network (LAN).
answer
NIC
question
________ are instructions to the computer.
answer
Software Programs
question
Computer can execute the code in ________.
answer
machine language
question
________ translates high-level language program into machine language program.
answer
A compiler
question
________ is an operating system.
answer
Windows XP
question
________ is a program that runs on a computer to manage and control a computer's activities.
answer
Operating system
question
Java was developed by ________.
answer
Sun Microsystems
question
Java ________ can run from a Web browser.
answer
applets
question
________is an object-oriented programming language.
answer
Java C++
question
________is interpreted.
answer
Java
question
________is Architecture-Neutral.
answer
Java
question
________is a technical definition of the language that includes the syntax and semantics of the Java programming language.
answer
Java language specification
question
________ contains predefined classes and interfaces for developing Java programs.
answer
Java API
question
________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
answer
Java JDK
question
________provides an integrated development environment (IDE) for rapidly developing Java programs. Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.
answer
Java IDE
question
The main method header is written as:
answer
public static void main(String[ ] args)
question
Which of the following statements is correct? 1) Every line in a program must end with a semicolon. 2) Every statement in a program must end with a semicolon. 3) Every comment line must end with a semicolon. 4) Every method must end with a semicolon. 5) Every class must end with a semicolon.
answer
Every statement in a program must end with a semicolon.
question
Which of the following statements is correct to display Welcome to Java on the console? (Choose all that apply.) 1) System.out.println('Welcome to Java'); 2) System.out.println("Welcome to Java"); 3) System.println('Welcome to Java'); 4) System.out.print('Welcome to Java'); 5) System.out.print("Welcome to Java");
answer
System.out.println("Welcome to Java"); System.out.print("Welcome to Java");
question
The JDK command to compile a class in the file Test.java is
answer
javac Test.java
question
Which JDK command is correct to run a Java application in ByteCode.class?
answer
java ByteCode
question
Java compiler translates Java source code into ________.
answer
Java bytecode
question
________ is a software that interprets Java bytecode.
answer
Java virtual machine
question
Suppose you define a Java class as follows: public class Test{ } In order to compile this program, the source code should be stored in a file named
answer
Test.java
question
The extension name of a Java bytecode file is
answer
.class
question
The extension name of a Java source code file is
answer
.java
question
Which of the following lines is not a Java comment? (Choose all that apply.) 1) /** comments */ 2) // comments 3) -- comments 4) /* comments */ 5) ** comments **
answer
-- comments ** comments **
question
the reserved words
answer
public static void class
question
Every statement in Java ends with ________.
answer
a semicolon (;)
question
A block is enclosed inside ________.
answer
braces
question
The ________ method displays a message dialog box.
answer
JOptionPane.showMessageDialog(null, "Welcome to Java!", "Example 1.2 Output", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "Welcome to Java!");
question
To use JOptionPane in your program, you may import it using:
answer
import javax.swing.JOptionPane; import javax.swing.*;
question
Consider the following statement: System.out.println("1 big bad wolft8 the 3 little pigsn4 dinnerr2night"); This statement will output ________ lines of text
answer
2
question
If you want to output the text "hi there", including the quote marks, which of the following could do that?
answer
System.out.println(""hi there"");
question
The word println is a(n)
answer
method
question
A Java variable is the name of a
answer
data value stored in memory that can change its value but cannot change its type during the program's execution
question
Of the following types, which one cannot store a numeric value? 1) int 2) byte 3) float 4) char 5) all of these can store numeric values
answer
char
question
What value will z have if we execute the following assignment statement? float z = 5 / 10;
answer
z will equal 0.0
question
A cast is required in which of the following situations? 1) using charAt to take an element of a String and store it in a char 2) storing an int in a float 3) storing a float in a double 4) storing a float in an int 5) all of these require casts
answer
storing a float in an int
question
If x is an int and y is a float, all of the following are legal except which assignment statement? 1) y = x; 2) x = y; 3) y = (float) x; 4) x = (int) y; 5) all of these are legal
answer
x = y;
question
Given the following assignment statement, which of the following answers is true regarding the order that the operators will be applied based on operator precedence? a = (b + c) * d / e - f;
answer
+, *, /, -
question
What will be the result of the following assignment statement? Assume b = 5 and c = 10. int a = b * (-c + 2) / 2;
answer
-20
question
is true regarding the mod operator, %
answer
It can be performed on any numeric values, and the result always is numeric
question
What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5?
answer
15
question
What is output with the statement System.out.println(""+x+y); if x and y are int values where x=10 and y=5?
answer
15
question
If you want to store into the String name the value "George Bush", you would do which statement?
answer
1) String name = "George Bush"; 2) String name = new String("George Bush"); 3) String name = "George" + " " + "Bush"; 4) String name = new String("George" + " " + "Bush");
question
Consider having three String variables a, b, and c. The statement c = a + b; also can be achieved by saying
answer
c = a.concat(b);
question
If the String major = "Computer Science", what is returned by major.charAt(1)?
answer
'o'
question
Which of the following would return the last character of the String x? 1) x.charAt(0); 2) x.charAt(last); 3) x.charAt(length(x)); 4) x.charAt(x.length( )-1); 5) x.charAt(x.length( ));
answer
x.charAt(x.length( )-1);
question
Suppose that String name = "Frank Zappa". What will the instruction name.toUpperCase( ).replace('A', 'I'); return?
answer
"FRINK ZIPPI"
question
Which library package would you import to use NumberFormat and DecimalFormat?
answer
java.text
question
Which library package would you import to use the class Random?
answer
java.util
question
The Random class has a method nextFloat( ) which returns a random float value between
answer
0 and 1
question
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?
answer
"0.0"
question
Consider the double value likelihood = 0.013885. What would be output if DecimalFormat dformatter = DecimalFormat("0.00##"); and you execute System.out.println(df.format(likelihood)); ?
answer
0.0139
question
Using getCurrencyInstance( ) formats a variable, automatically inserting
answer
decimal point for cents dollar sign percent sign
question
What value will z have if we execute the following assignment statement? int z = 50 / 10.00;
answer
a run-time error arises because z is an int and 50 / 10.00 is not
question
Since you cannot take the square root of a negative number, you might use which of the following instructions to find the square root of the variable x?
answer
Math.sqrt(Math.abs(x));
question
Assume that x is a double that stores 0.362491. To output this value as 36%, you could use the NumberFormat class with NumberFormat nf = NumberFormat.getPercentInstance( ); Which of the following statements then would output x as 36%?
answer
System.out.println(nf.format(x));
question
If you want to draw a red circle inside of a green square in an applet where the paint method is passed a Graphics object called page, which of the following sets of commands might you use?
answer
page.setColor(Color.green); page.fillRect(50, 50, 100, 100); page.setColor(Color.red); page.fillOval(60, 60, 80, 80);
question
You specify the shape of an oval in a Java applet by defining the oval's
answer
bounding box
question
In order to create a constant, you would use which of the following Java reserved words?
answer
final
question
If a, b, and c are int variables with a = 5, b = 7, c = 12, then the statement int z = (a * b - c) / a; will result in z equal to
answer
4
question
Java is a strongly typed language. What is meant by "strongly typed"?
answer
Every variable has a single type associated with it throughout its existence in the program, and the variable can only store values of that type
question
As presented in the Software Failure, the root cause of the Mars Climate Orbiter problem was
answer
a communication issue between subsystems
question
Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use to read an int value?
answer
input.nextInt();
question
The following code fragment reads in two numbers: (Choose all that apply.) Scanner input = new Scanner(System.in); int i = input.nextInt(); double d = input.nextDouble(); What are the correct ways to enter these two numbers?
answer
Enter an integer, a space, a double value, and then the Enter key. Enter an integer, two spaces, a double value, and then the Enter key. Enter an integer, an Enter key, a double value, and then the Enter key.
question
Every letter in a Java keyword is in lowercase.
answer
true
question
Which of the following is a valid identifier? (Choose all that apply.) 1) $343 2) class 3) 9X 4) 8+9 5) radius
answer
$343 radius
question
Which of the following are correct names for variables according to Java naming conventions? (Choose all that apply.) 1) radius 2) Radius 3) RADIUS 4) findArea 5) FindArea
answer
1) radius 4) findArea
question
Which of the following are correct ways to declare variables? (Choose all that apply.) 1) int length; int width; 2) int length, width; 3) int length; width; 4) int length, int width;
answer
1) int length; int width; 2) int length, width;
question
________ is the Java assignment operator.
answer
=
question
To assign a value 1 to variable x, you write
answer
x = 1;
question
Which of the following assignment statements is incorrect? (Choose all that apply.) 1) i = j = k = 1; 2) i = 1; j = 1; k = 1; 3) i = 1 = j = 1 = k = 1; 4) i == j == k == 1;
answer
3) i = 1 = j = 1 = k = 1; 4) i == j == k == 1;
question
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
answer
final double MAX_LENGTH = 99.98;
question
Which of the following is a constant, according to Java naming conventions? (Choose all that apply.) 1) MAX_VALUE 2) Test 3) read 4) ReadInt 5) COUNT
answer
MAX_VALUE COUNT
question
To improve readability and maintainability, you should declare ________ instead of using literal values such as 3.14159.
answer
constants
question
Which of these data types requires the most amount of memory? 1) long 2) int 3) short 4) byte
answer
long
question
To declare an int variable number with initial value 2, you write
answer
int number = 2;
question
What is the result of 45 / 4?
answer
11
question
Which of the following expressions will yield 0.5? (Choose all that apply.) 1) 1 / 2 2) 1.0 / 2 3) (double) (1 / 2) 4) (double) 1 / 2 5) 1 / 2.0
answer
1.0 / 2 (double) 1 / 2 1 / 2.0
question
Which of the following expression results in a value 1? 1) 2 % 1 2) 15 % 4 3) 25 % 5 4) 37 % 6
answer
37 % 6
question
24 % 5 is ________.
answer
4
question
-24 % 5 is ________.
answer
-4
question
-24 % -5 is ________.
answer
-4
question
To add a value 1 to variable x, you write (Choose all that apply.) 1) 1 + x = x; 2) x += 1; 3) x := 1; 4) x = x + 1; 5) x = 1 + x;
answer
x += 1; x = x + 1; x = 1 + x;
question
To add number to sum, you write (Note: Java is case-sensitive) (Choose all that apply.) 1) number += sum; 2) number = sum + number; 3) sum = Number + sum; 4) sum += number; 5) sum = sum + number;
answer
sum += number; sum = sum + number;
question
Suppose x is 1. What is x after x += 2?
answer
3
question
What is x after the following statements? int x = 1; int y = 2; x *= y + 1;
answer
x is 3
question
What is x after the following statements? int x = 1; x *= x + 1;
answer
x is 2
question
Math.pow(2, 3) returns ________.
answer
8.0
question
The ________ method returns a raised to the power of b.
answer
Math.pow(a, b)
question
To assign a double variable d to a float variable x, you write
answer
x = (float)d;
question
What is the printout of the following code: double x = 5.5; int y = (int)x; System.out.println("x is " + x + " and y is " + y);
answer
x is 5.5 and y is 5
question
Which of the following assignment statements is illegal? (Choose all that apply.) 1) float f = -34; 2) int t = 23; 3) short s = 10; 4) int t = (int)false; 5) int t = 4.5;
answer
int t = (int)false; int t = 4.5;
question
What is the value of (double)5/2?
answer
2.5
question
What is the value of (double)(5/2)?
answer
2.0
question
The expression (int)(76.0252175 * 100) / 100 evaluates to ________.
answer
76
question
If you attempt to add an int, a byte, a long, and a double, the result will be a ________ value.
answer
double
question
Which of the following is the correct expression of character 4?
answer
'4'
question
A Java character is stored in ________.
answer
two bytes
question
Suppose x is a char variable with a value 'b'. What is the printout of the statement System.out.println(++x)?
answer
c
question
Which of the following statement prints smithexam1test.txt?
answer
System.out.println("smithexam1test.txt");
question
Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i? 1) System.out.println(i); 2) System.out.println((char)i); 3) System.out.println((int)i); 4) System.out.println(i + " ");
answer
3) System.out.println((char)i);
question
The Unicode of 'a' is 97. What is the Unicode for 'c'?
answer
99
question
Will System.out.println((char)4) display 4?
answer
No
question
What is the printout of System.out.println('z' - 'a')?
answer
25
question
An int variable can hold ________. (Choose all that apply.) 1) 'x' 2) 120 3) 120.0 4) "x" 5) "120"
answer
'x' 120
question
Which of the following assignment statements is correct? (Choose all that apply.) 1) char c = 'd'; 2) char c = 100; 3) char c = "d"; 4) char c = "100";
answer
char c = 'd'; char c = 100;
question
The expression "Java " + 1 + 2 + 3 evaluates to ________.
answer
Java 123
question
Note that the Unicode for character A is 65. The expression "A" + 1 evaluates to ________.
answer
A1
question
Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
answer
66
question
The System.currentTimeMillis() returns ________.
answer
the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
question
Programming style is important, because ________. (Choose all that apply.) 1) a program may not compile if it has a bad style 2) good programming style can make a program run faster 3) good programming style makes a program more readable 4) good programming style helps reduce programming errors
answer
good programming style makes a program more readable good programming style helps reduce programming errors
question
According to Java naming convention, which of the following names can be variables? (Choose all that apply.) 1) FindArea 2) findArea 3) totalLength 4) TOTAL_LENGTH 5) class
answer
findArea totalLength
question
If a program compiles fine, but it produces incorrect result, then the program suffers ________.
answer
a logic error
question
The ________ method displays an input dialog for reading a string. (Choose all that apply.) 1) String string = JOptionPane.showMessageDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); 2) String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); 3) String string = JOptionPane.showInputDialog("Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); 4) String string = JOptionPane.showInputDialog(null, "Enter a string"); 5) String string = JOptionPane.showInputDialog("Enter a string");
answer
2) String string = JOptionPane.showInputDialog(null, "Enter a string", "Input Demo", JOptionPane.QUESTION_MESSAGE); 4) String string = JOptionPane.showInputDialog(null, "Enter a string"); 5) String string = JOptionPane.showInputDialog("Enter a string");
question
The ________ method parses a string s to an int value.
answer
Integer.parseInt(s);
question
The ________ method parses a string s to a double value.
answer
Double.parseDouble(s);
question
In Java a variable may contain
answer
a value or a reference
question
If two variables contain aliases of the same object then
answer
answers the object may be modified using either alias and the object will become an "orphan" if both variables are set to null are correct
question
Which properties are true of String objects? 1) Their lengths never change 2) The shortest string has zero length 3) Individual characters within a String may be changed using the replace method 4) The index of the first character in a string is one 5) Only Their lengths never change and The shortest string has zero length are true
answer
Only Their lengths never change and The shortest string has zero length are true
question
What happens if you attempt to use a variable before it has been initialized?
answer
Answers A syntax error may be generated by the compiler and A runtime error may occur during execution are correct
question
What is the function of the dot operator?
answer
Both, It allows one to access the data within an object when given a reference to the object and It allows one to invoke a method within an object when given a reference to the object are correct
question
In Java, "instantiation" means
answer
creating a new object of the class
question
In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?
answer
XINSTXIN.
question
Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.
answer
The program won't compile-you'll receive a syntax error about the missing class.
question
What will be displayed by this command: System.out.println(Math.pow(3, 3-1));
answer
9
question
An "alias" is when
answer
two different reference variables refer to the same physical object
question
The String class' compareTo method
answer
yields 0 if the two strings are identical
question
An API is
answer
an Application Programming Interface
question
The advantage(s) of the Random class' pseudo-random number generators, compared to the Math.random method, is that
answer
you may create several random number generators you can generate random ints, floats, and ints within a range you can initialize and reinitialize Random generators
question
Java.text's NumberFormat class includes methods that
answer
allow you to format currency, allow you to format percentages, round their display during the formatting process, but not truncate their display during the formatting process
question
The advantages of the DecimalFormat class compared with the NumberFormat class include
answer
only precise control over the number of digits to be displayed and control over the presence of a leading zero
question
Consider the following enumeration enum Speed { FAST, MEDIUM, SLOW };
answer
The name of the Speed enumeration whose ordinal value is zero is FAST
question
What is the advantage of putting an image in a JLabel instance?
answer
It becomes part of the component and is laid out automatically
question
What is the function of a frame's pack method?
answer
It sets the size appropriately for display
question
Layout managers are associated with
answer
containers
question
A containment hierarchy is
answer
a nested collection of relationships among containers
question
The main difference between a frame and a panel is
answer
frames can have a title bar; panels cannot
question
The Swing package
answer
is complementary to the AWT
question
Autoboxing is
answer
the automatic conversion of a wrapper object to/from its corresponding primitive type
question
In addition to their usage providing a mechanism to convert (to box) primitive data into objects, what else do the wrapper classes provide?
answer
static constants
question
A JPanel can be added to a JFrame to form a GUI. In order to place other GUI components such as JLabels and Buttons into the JFrame, which of the following messages is passed to the JPanel? 1) insert 2) include 3) get 4) getContentPane 5) add
answer
add
question
Which of the following GUI components is used to accept input into a JFrame? 1) JLabel 2) JPanel 3) JInput 4) JTextField 5) JInputField
answer
JTextField
question
JOptionPane is a class that provides GUI
answer
dialog boxes
question
The behavior of an object is defined by the object's
answer
methods
question
The relationship between a class and an object is best described as
answer
objects are instances of classes
question
To define a class that will represent a car, which of the following definitions is most appropriate? 1) private class car 2) public class car 3) public class Car 4) public class CAR 5) private class Car
answer
public class Car
question
Which of the following reserved words in Java is used to create an instance of a class? 1) class 2) public 3) public or private, either could be used 4) import 5) new
answer
new
question
In order to preserve encapsulation of an object, we would do all of the following except for which one?
answer
Make the class final
question
If a method does not have a return statement, then
answer
it must be a void method
question
Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?
answer
m2
question
A variable whose scope is restricted to the method where it was declared is known as a(n)
answer
local variable
question
A class' constructor usually defines
answer
how an object is initialized
question
Having multiple class methods of the same name where each method has a different number of or type of parameters is known as
answer
method overloading
question
Instance data for a Java class
answer
may be primitive types or objects
question
An example of passing message to a String where the message has a String parameter would occur in which of the following messages? 1) length 2) substring 3) equals 4) toUpperCase 5) none of these, it is not possible to pass a String as a parameter in a message to a String
answer
equals
question
Which of the following could be used to instantiate a new Student s1? 1) Student s1 = new Student( ); 2) s1 = new Student( ); 3) Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33); 4) new Student s1 = ("Jane Doe", "Computer Science", 3.333, 33); 5) new Student(s1);
answer
Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33);
question
Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private.
answer
Because they will only be called from methods inside of Rational
question
StringTokenizer is a class in the java.util library that can divide a String based on some delimiter String (a delimiter is a separator). If the instruction StringTokener st = new StringTokenizer(str, "&&"); is executed, where str is some String, then st divides up str into separate Strings whenever
answer
two ampersands are found
question
Which of the following Applet methods is called automatically when the applet is first loaded? 1) Applet (the Applet's constructor) 2) init 3) start 4) getCodeBase 5) getImage
answer
init
question
Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal? 1) foo(0, 0.1); 2) foo(0 / 1, 2 * 3); 3) foo(0); 4) foo( ); 5) foo(1 + 2, 3 * 0.1);
answer
foo(0 / 1, 2 * 3);
question
Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal? 1) doublefoo(0); 2) doublefoo(0.555); 3) doublefoo(0.1 + 0.2); 4) doublefoo(0.1, 0.2); 5) all of these are legal except for doublefoo(0.1, 0.2);
answer
all of these are legal except for doublefoo(0.1, 0.2);
question
In a UML diagram for a class
answer
classes are represented as rectangles there may be a section containing the name of the class there may be a section containing the attributes (data) of the class there may be a section containing the methods of the class
question
Visibility modifiers include
answer
public, private, protected
question
The expressions that are passed to a method in an invocation are called
answer
actual parameters
question
What are the objects needed in order to create a Java GUI (graphical user interface)? 1) components 2) events 3) listeners 4) all of these 5) only classes from AWT and/or Swing are needed
answer
all of these
question
What happens if you declare a class constructor to have a void return type?
answer
You'll likely receive a syntax error
question
The software failure at the Denver International Airport's baggage handling system is a good example of 1) how a large system can be obsolete by the time it is developed 2) how designers sometimes have too much faith in the technology they are using 3) how failures are often a result of multiple variables caused by a system as a whole in actual operation 4) how the use of a centralized computer is really unrealistic in today's distributed processing 5) all of these
answer
all of these
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New