| | |
Need help with T/F and Multiple Choice
![]() |
•
•
Join Date: Mar 2008
Posts: 3
Reputation:
Solved Threads: 0
Part I True/False ( 40 points , 2 point each)
1. If you have created an exception class, you can define other exception classes
extending the definition of the exception class you created.
2. Using the mechanism of inheritance, every public member of the class Object can be
overridden and/or invoked by every object of any class type.
3. If a class is declared final, then no other class can be derived from this class.
4. The class Throwable contains constructor(s).
5. You can instantiate an object of a subclass of an abstract class, but only if the subclass gives the definitions of all the abstract methods of the superclass.
6. Every program with a try block must end with a finally block.
7. If there is a finally block after the last catch block, the finally block always executes.
8. Making a reference to an object that has not yet been instantiated would throw an exception from the NullPointerException class.
9. If you have created an exception class, you can define other exception classes extending the efinition of the exception class you created.
10. The layout manager FlowLayout places components in the container from left to right until no more items can be placed.
11. The class Container is the superclass of all the classes designed to provide a GUI.
12. JTextAreas can be used to display multiple lines of text.
13. The StringIndexOutOfBoundsException could be thrown by the method parseInt of the class Integer.
14. The class RuntimeException is part of the package java.io.
15. If an exception occurs in a try block and that exception is caught by a catch block, then the remaining catch blocks associated with that try block are ignored.
16. The order in which catch blocks are placed in a program has no impact on which catch block is executed.
17. The methods getMessage and printStackTrace are private methods of the class Throwable.
18. If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal parameter and actual parameter.
19. If a member of a class is a method, it can (directly) access any member of the class.
20. You must always use the reserved word super to use a method from the superclass in the subclass.
Part II Multiple Choice : (30 points, 2 points each)
1. An abstract class can contain ____.
a. only abstract methods c. abstract and non-abstract methods
b. only non-abstract methods d. nothing
2. An abstract method ____.
a. is any method in the abstract class
b. cannot be inherited
c. has no body
d. is found in a subclass and overrides methods in a superclass using the reserved
word abstract
3. If a class implements an interface, it must ____.
a. provide definitions for each of the methods of the interface
b. override all constants from the interface
c. rename all the methods in the interface
d. override all variables from the interface
4. Which of the following is the default layout manager for a Java application?
a. null c. FlowLayout
b. GridLayout d. BorderLayout
5. Java will automatically define a constructor
a. if the programmer does not define a default constructor for a class
b. if the programmer does not define any constructors for a class
c. if the program refers to a constructor with no parameters
d. for every class defined in a program
6. How many finally blocks can there be in a try/catch structure?
a. There must be 1.
b. There can be 1 following each catch block.
c. There can be 0 or 1 following the last catch block.
d. There is no limit to the number of finally blocks following the last catch block.
7. What happens in a method if there is an exception thrown in a try block but there is no catch block but a finally block following the try block?
a. The program ignores the exception.
b. The program will not compile without a complete try/catch structure.
c. The program terminates immediately.
d. The program throws an exception and proceeds to execute the finally block.
8. An exception that can be analyzed by the compiler is a(n) ____.
a. unchecked exception c. compiler exception
b. checked exception d. execution exception
9 - 12 Base on the following code :
import java.util.*;
public class ExceptionExample1
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int dividend, divisor, quotient;
try
{
System.out.print("Enter dividend: ");
dividend = console.nextInt();
System.out.println();
System.out.print("Enter divisor: ");
divisor = console.nextInt();
System.out.println();
quotient = dividend / divisor;
System.out.println("quotient = " + quotient);
}
catch (ArithmeticException aeRef)
{
System.out.println("Exception" + aeRef.toString());
}
catch (InputMismatchException imeRef)
{
System.out.println("Exception "
+ imeRef.toString());
}
catch( IOException ioeRef)
{
System.out.println("Exception "
+ ioeRef.toString());
}
9. Which of the following will cause the first exception to occur in the code above?
a. if the divisor is zero
b. if the dividend is zero
c. if the quotient is zero
d. This code will not compile so an exception cannot be triggered.
10. Which of the following inputs would be caught by the second catch block in the program
above?
a. 0 c. h3
b. 10 d. -1
11. Which method throws the second exception in the code above?
a. nextInt c. println
b. toString d. nextLine
12. Which of the following methods prints a list of the methods that were called before the
exception was thrown?
a. getMessage() c. printStackTrace()
b. printCalledMethods() d. traceMethodStack()
13. How would the three classes, Undergraduate, Graduate, and Student interrelate if we are determined to use inheritance in the class definitions?
a. Student would be a subclass of Undergraduate, which would be a subclass of Graduate.
b. Graduate would be a subclass of Undergraduate, which would be a subclass of Student.
c. Graduate would be a subclass of Student, and Undergraduate would be a subclass of Graduate.
d. Undergraduate and Graduate would both be subclasses of Student.
14. . Which of the following types of methods cannot be declared as abstract?
a. Private methods
b. Static methods
c. a and b
d. neither a nor b
15. What happens when an expression uses == to compare two string variables?
a. The value of the expression will be true if both strings have the same characters in them.
b. The value of the expression will be true if both string variables refer to the same object.
c. The expression will not be correct syntax and the program will not compile.
d A run-time error will occur.
1. If you have created an exception class, you can define other exception classes
extending the definition of the exception class you created.
2. Using the mechanism of inheritance, every public member of the class Object can be
overridden and/or invoked by every object of any class type.
3. If a class is declared final, then no other class can be derived from this class.
4. The class Throwable contains constructor(s).
5. You can instantiate an object of a subclass of an abstract class, but only if the subclass gives the definitions of all the abstract methods of the superclass.
6. Every program with a try block must end with a finally block.
7. If there is a finally block after the last catch block, the finally block always executes.
8. Making a reference to an object that has not yet been instantiated would throw an exception from the NullPointerException class.
9. If you have created an exception class, you can define other exception classes extending the efinition of the exception class you created.
10. The layout manager FlowLayout places components in the container from left to right until no more items can be placed.
11. The class Container is the superclass of all the classes designed to provide a GUI.
12. JTextAreas can be used to display multiple lines of text.
13. The StringIndexOutOfBoundsException could be thrown by the method parseInt of the class Integer.
14. The class RuntimeException is part of the package java.io.
15. If an exception occurs in a try block and that exception is caught by a catch block, then the remaining catch blocks associated with that try block are ignored.
16. The order in which catch blocks are placed in a program has no impact on which catch block is executed.
17. The methods getMessage and printStackTrace are private methods of the class Throwable.
18. If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal parameter and actual parameter.
19. If a member of a class is a method, it can (directly) access any member of the class.
20. You must always use the reserved word super to use a method from the superclass in the subclass.
Part II Multiple Choice : (30 points, 2 points each)
1. An abstract class can contain ____.
a. only abstract methods c. abstract and non-abstract methods
b. only non-abstract methods d. nothing
2. An abstract method ____.
a. is any method in the abstract class
b. cannot be inherited
c. has no body
d. is found in a subclass and overrides methods in a superclass using the reserved
word abstract
3. If a class implements an interface, it must ____.
a. provide definitions for each of the methods of the interface
b. override all constants from the interface
c. rename all the methods in the interface
d. override all variables from the interface
4. Which of the following is the default layout manager for a Java application?
a. null c. FlowLayout
b. GridLayout d. BorderLayout
5. Java will automatically define a constructor
a. if the programmer does not define a default constructor for a class
b. if the programmer does not define any constructors for a class
c. if the program refers to a constructor with no parameters
d. for every class defined in a program
6. How many finally blocks can there be in a try/catch structure?
a. There must be 1.
b. There can be 1 following each catch block.
c. There can be 0 or 1 following the last catch block.
d. There is no limit to the number of finally blocks following the last catch block.
7. What happens in a method if there is an exception thrown in a try block but there is no catch block but a finally block following the try block?
a. The program ignores the exception.
b. The program will not compile without a complete try/catch structure.
c. The program terminates immediately.
d. The program throws an exception and proceeds to execute the finally block.
8. An exception that can be analyzed by the compiler is a(n) ____.
a. unchecked exception c. compiler exception
b. checked exception d. execution exception
9 - 12 Base on the following code :
import java.util.*;
public class ExceptionExample1
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
int dividend, divisor, quotient;
try
{
System.out.print("Enter dividend: ");
dividend = console.nextInt();
System.out.println();
System.out.print("Enter divisor: ");
divisor = console.nextInt();
System.out.println();
quotient = dividend / divisor;
System.out.println("quotient = " + quotient);
}
catch (ArithmeticException aeRef)
{
System.out.println("Exception" + aeRef.toString());
}
catch (InputMismatchException imeRef)
{
System.out.println("Exception "
+ imeRef.toString());
}
catch( IOException ioeRef)
{
System.out.println("Exception "
+ ioeRef.toString());
}
9. Which of the following will cause the first exception to occur in the code above?
a. if the divisor is zero
b. if the dividend is zero
c. if the quotient is zero
d. This code will not compile so an exception cannot be triggered.
10. Which of the following inputs would be caught by the second catch block in the program
above?
a. 0 c. h3
b. 10 d. -1
11. Which method throws the second exception in the code above?
a. nextInt c. println
b. toString d. nextLine
12. Which of the following methods prints a list of the methods that were called before the
exception was thrown?
a. getMessage() c. printStackTrace()
b. printCalledMethods() d. traceMethodStack()
13. How would the three classes, Undergraduate, Graduate, and Student interrelate if we are determined to use inheritance in the class definitions?
a. Student would be a subclass of Undergraduate, which would be a subclass of Graduate.
b. Graduate would be a subclass of Undergraduate, which would be a subclass of Student.
c. Graduate would be a subclass of Student, and Undergraduate would be a subclass of Graduate.
d. Undergraduate and Graduate would both be subclasses of Student.
14. . Which of the following types of methods cannot be declared as abstract?
a. Private methods
b. Static methods
c. a and b
d. neither a nor b
15. What happens when an expression uses == to compare two string variables?
a. The value of the expression will be true if both strings have the same characters in them.
b. The value of the expression will be true if both string variables refer to the same object.
c. The expression will not be correct syntax and the program will not compile.
d A run-time error will occur.
what does Fetal Alcohol Spectrum Disorders (FASD) have to do with anything ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- multiple choice test (C)
- Multiple choice quiz (Visual Basic 4 / 5 / 6)
- Please Help me in finding multiple choice question with answer on data structure. (Computer Science)
- generate random question (C)
- who wants to be a millionare!!!!!!!! (Java)
- Receive Multiple Security Messages In IE. (Web Browsers)
- What is your hosting plan? :) (Networking Hardware Configuration)
- Change in Certification Policy NT vs 2000 (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Urgent, Please help me
- Next Thread: StringTokenizer problem
| Thread Tools | Search this Thread |
actuate add android api applet application applications array arrays automation balls bank binary bluetooth business chat class clear client code codesnippet collections component database defaultmethod development dice digit dragging ebook eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health hql html hyper ide idea image infinite int integer invokingapacheantprogrammatically j2me java javame javaprojects jni jpanel julia linux list main map method methods mobile myregfun mysql netbeans nonstatic openjavafx parameter pearl php problem program project recursion repositories scanner scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string sun superclass swing swt thread threads tree windows






