Test 2 Flashcards
An instance of ________ describes system errors. If this type of error occurs, there is little you can do beyond notifying the user and trying to terminate the program gracefully.
Error
An instance of ________ describes programming errors, such as bad casting, accessing an out-of-bounds array, and numeric errors.
RuntimeException
If an exception occurs in a try-catch block, the code in the finally clause is ________.
executed
The FileWriter, FileReader, FileInputStream, FileOutputStream, and RandomAccessFile classes can be used to process external files. (T/F)
True
Closing an OutputStream ensures that the data in the buffer are sent to the destination. (T/F)
True
Which of the following is a correct interface?
Question options:
A) interface A { void print();}
B) abstract interface A { print(); }
C) interface A { void print() { }; }
D) abstract interface A { abstract void print() { };}
A) interface A { void print();}
Which of the following class definitions defines a legal abstract class?
A) abstract class A { abstract void unfinished(); }
B) class A { abstract void unfinished() { } }
C) public class abstract A { abstract void unfinished(); }
D) class A { abstract void unfinished(); }
A) abstract class A { abstract void unfinished(); }
Polymorphism means ________.
that a variable of supertype can refer to a subtype object
Show the output of running the class Test in the following code lines:
interface A { } class C { } class B extends D implements A { } public class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); } } class D extends C { }
b is an instance of A followed by b is an instance of C.
Which class do you use to write data into a text file?
PrintWriter
Which method can be used to read a whole line from the file?
nextLine
Assume Calendar calendar = new GregorianCalendar(). ________ returns the week of the year.
calendar.get(Calendar.WEEK_OF_YEAR)
Given the following code:
class C1 {} class C2 extends C1 { } class C3 extends C2 { } class C4 extends C1 {}
C1 c1 = new C1(); C2 c2 = new C2(); C3 c3 = new C3(); C4 c4 = new C4();
Which of the following expressions evaluates to false? A) c2 instanceof C1 B) c1 instanceof C1 C) c4 instanceof C2 D) c3 instance of C1
c4 instanceof C2
It is a compilation error if two methods differ only in return type in the same class. (T/F)
True
To override a method, the method must be defined in the subclass using the same signature and compatible return type as in its superclass. (T/F)
True
Overloading a method is to provide more than one method with the same name but with different signatures to distinguish them. (T/F)
True
A static method cannot be overridden. If a static method defined in the superclass is redefined in a subclass, the method defined in the superclass is hidden. (T/F)
True
A private method cannot be overridden. If a method defined in a subclass is private in its superclass, the two methods are completely unrelated. (T/F)
True
What is the output of the following code?
public class Test { public static void main(String[] args) { String s1 = new String("Java"); String s2 = new String("Java"); System.out.print((s1 == s2) + " " + (s1.equals(s2))); } }
false true
Every object is an instance of the Object class. (T/F)
True
Inheritance means ________.
that a class can extend another class
The UML uses ________ before a member name to indicate that the member is protected (protected modifier).
hashtag symbol
Which of the following class definitions defines a legal abstract class?
A) abstract class A { abstract void unfinished(); }
B) public class abstract A { abstract void unfinished(); }
C) class A { abstract void unfinished() { } }
D) class A { abstract void unfinished(); }
A) abstract class A { abstract void unfinished(); }
What is the best suitable relationship between Employee and Faculty?
Inheritance