Advanced Java Programming

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

An instance of __________ describes programming errors, such as bad casting and out-of-bounds array indexing. Select one: A. RuntimeException B. Exception C. Error D. Throwable

A

Which of the following statements are false? (select all that apply) Select one or more: A. A subclass is a subset of its parent class. B. A subclass usually contains more attributes and/or behavior than its parent class. C. "class A extends B" means that A is a subclass of B. D. "class A extends B" means that B is a subclass of A.

A and D

Which of the following statements are false? (select all that apply) Select one or more: A. Binary files are dependent of the encoding scheme on the host computer. B. Text I/O involves encoding and decoding. C. Binary I/O does not require encoding and decoding. D. Text I/O is generally more efficient than binary I/O.

A and D

Which of the following statements are true? (select all that apply) Select one or more: A. A method may declare that it throws exceptions. B. To throw an exception we use the throw keyword. C. A method may throw multiple exceptions D. If a checked exception occurs in a method, it must either be caught or declared to be thrown from the method.

A, B, C, and D

Which of the following are considered whitespace characters when reading input with Scanner objects? (select all that apply) Select one or more: A. blanks B. tabs C. newlines D. commas

A, B, and C

To serialize an object yourself, which of these methods must you implement? (select all that apply) Select one or more: A. SerializeObject B. writeObject C. deserializeObject D. readObject

B and D

Which of the following statements are false? (select all that apply) Select one or more: A. The OutputStream class is an abstract base class of ObjectOutputStream. B. The FileStream class is a parent class of ObjectOutputStream. C. The ObjectOutputStream class can wrap a BufferedOutputStream. D. The ObjectStream class is a parent class of ObjectOutputStream.

B and D

Members of a base class that have __________ visibility and __________ visibility are accessible by subclasses. Select one or more: A. final B. private C. protected D. public

C and D

What are some invalid reasons to create an instance of the File class? (select all that apply) Select one or more: A. To determine whether a file exists. B. To obtain the properties of a file, such as whether a file is readable. C. To read data from a file. D. To write data to a file.

C and D

Which of the following statements are false? (select all that apply) Select one or more: A. The abstract keyword must be used in the class header (e.g., abstract class Person { ... }) to define an abstract class. B. Abstract classes cannot be instantiated. C. A subclass of an abstract class can always be instantiated. D. The Object super class is an abstract class.

C, and D

After the following program is finished, how many bytes are written to the file myFile.dat? import java.io.*; public class MyProgram{public static void main( String [] args ) throws IOException{DataOutputStream output = new DataOutputStream( new FileOutputStream( "myFile.dat" );output.writeInt( 1234 );output.writeChars( "hello" );output.close();}} Select one: A. 6 bytes B. 9 bytes C. 10 bytes D. 14 bytes

D

Consider the code below: 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? Select one: A. c1 instanceof C1 B. c2 instanceof C1 C. c3 instanceof C1 D. c4 instanceof C2

D

Consider the code below: class C1 { ... }class C2 extends C1 { ... }class C3 extends C2 { ... }class C4 extends C3 { ... } C1 c1 = new C1();C2 c2 = new C2();C3 c3 = new C3();C4 c4 = new C4(); Which of the following expressions evaluates to false? Select one or more: A. c1 instanceof C1 B. c2 instanceof C1 C. c3 instanceof C1 D. c4 instanceof C2

D

Consider the code below: public abstract class Animal{ public abstract void draw();} public class Cat extends Animal{ private String name = "Tiger"; public void draw() { System.out.println( "Drawing cat named " + name ); }} public class Frog extends Animal{ private String name = "Kermit"; public void draw() { System.out.println( "Printing frog named " + name ); }} public class MyProgram{ public static void main( String [] args ) { Animal [] myAnimals = { new Frog(), new Cat() }; myAnimals[0].draw(); myAnimals[1].draw(); }} Which of the following statements is false? I. The code will not compile and run because Animal is an abstract class. II. The code will compile and run correctly. III. The program attempts to use polymorphic behavior. Select one: A. I only B. II only C. III only D. II and III only

A

Given the following code, what will the output be? public interface Printable{ void print();} public class A implements Printable{ private String name = "A"; public void print() { System.out.println( "Printing object named " + name ); }} public class B implements Printable{ private String name = "B"; public void print() { System.out.println( "Printing object named " + name ); }} public class MyProgram{ public static void main( String [] args ) { Object [] objects = { new A(), new B() }; objects[0].print(); objects[1].print(); } } Select one: A. The program will not compile. B. The code will compile, but a runtime error will be generated. C. The program will compile and run, but no output will be produced. D. Printing object named APrinting object named B

A

The technique of connecting multiple streams in a class hierarchy (e.g., to connect a file with a stream and add buffering) is called __________. Select one: A. stream layering B. stream concatenation C. stream addition D. stream connecting

A

What exception type does the following program throw? public class MyProgram{public static void main( String [] args ){int x = 30;System.out.println( x / 0 );}} Select one: A. ArithmeticException B. IOException C. ClassCastException D. NullPointerException

A

What exception type does the following program throw? public class MyProgram{public static void main( String [] args ){int x = 30;int y = 0;System.out.println( x / y );}} Select one: A. ArithmeticException B. IOException C. ClassCastException D. NullPointerException

A

What is wrong in the following program? public static void myMethd( ){catch( ArithmeticException e ){System.out.println( "I love Java!!" );}} Select one: A. You cannot have a catch block without a try block. B. You cannot have a catch block without a try block or finally block. C. A method that does not declare exceptions cannot have a catch block. D. There is nothing wrong with the program.

A

When containment is used in an object-oriented design, which type of relationship is represented? Select one: A. has a B. referential C. inheritance D. is a

A

Which of the following is the correct mode for creating a RandomAccessFile stream that can be updated? Select one: A. "rw" B. "rwx" C. "a" D. "true"

A

Which of the following statements about abstract classes is true? Select one: A. They are typically used as building blocks. B. They are used to provide a consistent signature for invoking behavior. C. They can be instantiated like any other classes. D. None of the above are true.

A

Which of the following statements is true for the code below? public class MyProgram{public static void main( String [] args ){B myObj = new B();myObj.displayData();}} public class A{private int a;public A() {}public A( int x ) { a = x; }public int getA() { return a; }} public class B extends A{private int b;public void displayData(){System.out.println( "a = " + getA() + " b = " + b );}} Select one: A. The program output is a = 0 b = 0 B. The program will compile, but a runtime error will occur because a and b are not initialized C. The program will not compile because no constructor is defined for class B D. The program will not compile for reasons other than specified above

A

Which of the following statements is true? Select one: A. The getClass() method is defined in the Object super class. B. The getClass() method returns the name of a class. C. The equals (==) operator is defined for the Object super class. D. None of the above are true.

A

Which of the following statements is true? Select one: A. When an object is serialized, all of its data attributes may not always be serialized. B. When an object is serialized, its methods are also serialized. C. A class that is serialized must provide code implementations for the abstract methods in Serializable. D. Objects must be serializable in order to write their data attributes to files.

A

With which class can you append or update a file? Select one: A. RandomAccessFile B. OutputStream C. DataOutputStream D. None of the above

A

Which of the following statements are true? (select all that apply) Select one or more: A. ObjectInputStream permits input of primitive types in addition to objects. B. ObjectOutputStream permits output of primitive types in addition to objects. C. Objects of classes with any visibility (public, private, protected) are serializable. D. Stream layering cannot be used when serializing objects.

A and B

Which of the following can be used to create an output object for the file myFile.txt? (select all that apply) Select one or more: A. PrintWriter out = new PrintWriter( "myFile.txt" ); B. PrintWriter out = new PrintWriter( myFile.txt ); C. PrintWriter out = new PrintWriter( new File( "myFile.txt" ) ); D. PrintWriter out = new PrintWriter( File( "myFile.txt" ) );

A and C

Which of the following statements are false? (select all that apply) Select one or more: A. A method may not declare that it throws exceptions. B. To throw an exception we use the throw keyword. C. A method may not throw multiple exceptions D. If a checked exception occurs in a method, it must either be caught or declared to be thrown from the method.

A and C

Consider the code below: public class A{ private int x; public String toString() { return "A's value of x is " + x; }} public class MyProgram{ public static void main( String [] args ) { Object a1 = new A(); Object a2 = new Object(); System.out.println( a1.toString() ); System.out.println( a2.toString() ); } } Which of the following statements are false? (select all that apply) Select one or more: A. The program will not compile because Object a1 = new A() is illegal. B. The program won't compile because the toString() method in the statement a2.toString() is an abstract method. C. The program compiles and executes successfully. D. The program will compile, but a runtime error will be generated.

A, B, and D

Instances from these classes are unchecked exceptions. (select all that apply) Select one or more: A. RuntimeException B. Exception C. Error D. ArithmeticException

A, C, and D

Which of the following are not checked exceptions? (select all that apply) Select one or more: A. ArithmeticException B. IOException C. Error D. NullPointerException

A, C, and D

Which of the following is an incorrect interface definition? (select all that apply) Select one or more: A. interface A { void print() { }; } B. abstract interface A { print(); } C. abstract interface A { abstract void print() { }; } D. interface A { void print();

A,B, and C

Which of the following statements are true? (select all that apply) Select one or more: A. A subclass cannot extend more than one class, but it may implement any number of interfaces. B. An interface can extend any number of interfaces using the extends keyword. C. A subclass can extend any number of classes using the extends keyword. D. An interface can implement any number of interfaces using the implements keyword.

A,B, and C

Which of the following statements is false for the code below? (select all that apply) public class MyProgram{public static void main( String [] args ){B myObj = new B();myObj.myMethod( 5 );System.out.println( myObj.i );}} public class A{public int i;public void myMethod( int x ) { i = x; }} public class B extends A{public void myMethod( String s ) { }} Select one or more: A. The program has a compilation error because myMethod is overridden with a different signature in class B. B. The program has a compilation error because myObj.myMethod(5) cannot be invoked since myMethod is hidden in class B. C. The program has a runtime error because myObj.i is not legal. D. The method myMethod is not overridden in class B. Class B inherits myMethod from class A and defines an overloaded method called myMethod.

A,B, and C

Which of the following is an incorrect mode for creating a RandomAccessFile stream that can be updated? (select all that apply) Select one or more: A. "w" B. "r" C. "rw" D. "rwx"

A,B, and D

Which of the following statements regarding abstract methods are true? (select all that apply) Select one or more: A. They are used to provide a consistent signature for invoking behavior. B. They are used to help achieve polymorphic behavior. C. They are used to promote the reuse of existing code definitions. D. They do not require that immediate subclasses provide a code definition.

A,B, and D

The abstract keyword is not used to define which of the following? (select all that apply) Select one or more: A. constants B. enumerations C. no-op methods D. concrete super classes

A,B,C and D

Which of the following statements are false? (select all that apply) Select one or more: A. An object of one type cannot be used to reference an object of another type. B. A parent class is responsible for invoking its subclass constructor. C. Base classes are more specialized than their subclasses. D. A subclass can always access members of its parent class.

A,B,C and D

Which of the following statements are true? (select all that apply) Select one or more: A. Binary files are independent of the encoding scheme on the host computer. B. Text I/O involves encoding and decoding. C. Binary I/O does not require encoding and decoding. D. Binary I/O is generally more efficient than text I/O.

A,B,C,D

A Java Exception is not a subclass of these classes. (select all that apply) Select one or more: A. RuntimeException B. Executable C. Error D. Throwable

A,B,and C

What exception types are not thrown by the following program? (select all that apply) public class MyProgram{public static void main( String [] args ){int [] myArray = new int[4];for( int i = 0; i <= 4; i++ )System.out.println( myArray[i] );}} Select one or more: A. ArithmeticException B. ArrayIndexOutOfBoundsException C. NullPointerException D. LoopIndexBoundsException

A,C, and D

Which method can not be used to find out the number of bytes in a file using InputStream? (select all that apply) Select one or more: A. length() B. available() C. size() D. getSize()

A,C, and D

Which of the following statements does not correctly create a DataOutputStream to write to a file named out.dat? (select all that apply) Select one or more: A. DataOutputStream outfile = new DataOutputStream( new File( "out.dat" ) ); B. DataOutputStream outfile = new DataOutputStream( new FileOutputStream( "out.dat" ) ); C. DataOutputStream outfile = new DataOutputStream( FileOutputStream( "out.dat" ) ); D. DataOutputStream outfile = new DataOutputStream( "out.dat" );

A,C, and D

Which of the following statements are true? (select all that apply) Select one or more: A. Methods in the same class can be overloaded. B. A method can be overridden in the same class. C. If a method overloads another method, the two methods must have the same signature. D. If a method overrides another method, the two methods must have the same signature. E. A method in a subclass can overload a method in its superclass.

A,D, and E

Which of the following statements are true? (select all that apply) Select one or more: A. The getClass() method is defined in the Object super class. B. The getClass() method returns an object of type Class. C. The equals() method is defined in the Object super class. D. An instance of the Object class can reference an instance of any other class.

AB,C and D

Consider the code below: public interface MyInterface{ int myMethod(); protected final int MAX = 10;} public class MyClass implements MyInterface{ public int myMethod() { return MAX; }} public class MyProgram{ public static void main( String [] args ) { MyClass obj = new MyClass(); System.out.println( obj.myMethod() ); }} Which of the following statements is true? I. The program will not compile because the visibility of myMethod() is not explicitly specified. II. The program will not compile because MAX has protected visibility. III. The program will compile and run correctly. Select one: A. I only B. II only C. III only D. I and II only

B

Consider the following code: Scanner input = new Scanner( System.in );int n1 = input.nextInt();int n2 = input.nextInt();String s = input.nextLine(); Suppose you enter 36 58.2 123 and then press the ENTER key. Which of the following statements is true? Select one: A. After the last statement is executed, n1 is 23. B. The program has a runtime error because 58.2 is not an integer type. C. After the last statement is executed, s contains the characters '1', '2', '3', and '\n'. D. After the last statement is executed, s contains the characters '1', '2', '3'. E. The program will not compile.

B

Given the code below, which of the following statements is true? public interface I1 { void method1(); } public interface I2 { void method2(); } public class Animal { protected String name = "animal"; } public class Cat extends Animal implements I1, I2{ public void method1() { System.out.print( "I'm a cat" ); } public void method2() { name = "Gizmo"; System.out.print( " and my name is " + name ); }} public class Dog extends Animal implements I1, I2{ public void method1() { System.out.print( "I'm a dog" ); } public void method2() { name = "Snoopy"; System.out.println( " and my name is " + name ); }} public class MyProgram{ public static void main( String [] args ) { Animal [] myAnimals = { new Dog(), new Cat() }; for( int i = 0; i < 2; i++ ) { myAnimals[i].method1(); myAnimals[i].method2(); } }} Select one: A. The code won't compile because Cat and Dog can't simultaneously extend a class and implement multiple interfaces. B. The code won't compile for a reason other than above. C. The code compiles, but a runtime error will be generated. D. The code compiles and runs correctly.

B

Object-oriented programming allows you to derive new classes from existing classes. This is called __________. Select one: A. encapsulation B. inheritance C. abstraction D. generalization

B

The DataInputStream class can be used to read __________ files. Select one: A. primitive B. binary C. text D. character

B

What exception type does the following program throw? public class MyProgram{ {public static void main( String [] args ){int [] myArray = new int[10];System.out.println( myArray[10] );}} Select one: A. ArithmeticException B. ArrayIndexOutOfBoundsException C. NullPointerException D. LoopIndexBoundsException

B

What is wrong in the following program? public class MyProgram{public static void main( String [] args ){try{System.out.println( "Hello World" );}}} Select one: A. You cannot have a try block in the main method. B. You cannot have a try block without a catch block or finally block. C. A method call that does not declare exceptions cannot be placed inside a try block. D. There is nothing wrong with the program.

B

Which class is used to read data from a text file? Select one: A. File B. FileReader C. PrintReader D. BufferedInputReader

B

Which class is used to write data to a text file? Select one: A. File B. PrintWriter C. Scanner D. System

B

Which method can be used to find out the number of bytes in a file using InputStream? Select one: A. length() B. available() C. size() D. getSize()

B

Which of the following can be used to prevent a method from being overridden? Select one: A. const B. final C. super D. private

B

Which of the following interface definitions will compile correctly? interface InterfaceA{public abstract void funcA();void funcB();private void myFunc();double CONSTA = 111;}interface InterfaceB{void func1();void func2();void func3();} Select one: A. InterfaceA only B. InterfaceB only C. Both interfaces will compile. D. Neither of the interfaces will compile.

B

Which of the following statements is true? I. Java interfaces may not be passed as method arguments. II. It is permissible to have arrays of interfaces (e.g., MyInterface [] array ) III. The abstract keyword must be used when declaring the methods in an interface. Select one: A. I only B. II only C. III only D. I and II only E. II and III only

B

Which of the following statements is true? Select one: A. The abstract keyword need not be used in the class header (e.g., abstract class Person { ... }) to define an abstract class. B. Abstract classes cannot be instantiated. C. A subclass of an abstract class can always be instantiated. D. The Object super class is an abstract class.

B

Consider the code below: public class Parent{private int x;private int y;public Parent( int a, int b ) { ... }...} public class Child extends Parent{private int z;public Child( int a, int b, int c ) { ... }...} Which of the following are required in order for the Child class to be serializable? (select all that apply) Select one or more: A. The Child class must have a default constructor. B. The Child class must implement Serializable. C. The Child class must be responsible for serializing x and y. D. The Child class cannot be made serializable.

B and C

Which of the following statements are false? (select all that apply) Select one or more: A. Methods in the same class can be overloaded. B. A method can be overridden in the same class. C. If a method overloads another method, the two methods must have the same signature. D. If a method overrides another method, the two methods must have the same signature. E. A method in a subclass can overload a method in its superclass.

B and C

Which of the following statements are false? (select all that apply) Select one or more: A. Writing an object to a file is called serializing an object. B. A parent class must be serializable in order for one of its child classes to be serializable. C. Reading an object from a file is called deserializing an object. D. It is not possible to serialize classes yourself.

B and C

For the code below, and assuming widget.dat exists, which of the following statements are false? (select all that apply) // assume all appropriate packages have been imported public class Widget implements Serializable{private int x;public void setX( int d ) { x = d; }public int getX() { return x; }} public class MyProgram {public static void main( String [] args ) throws Exception { ObjectInputStream in = new ObjectInputStream( new FileInputStream( "widget.dat" ) ); Widget w = (Widget) in.readObject(); System.out.println( w.getX() ); }} Select one or more: A. The program output is 0. B. The program will not compile. C. The program will compile, but a runtime error will occur because readObject returns an instance of Object. D. The program will compile and run, but no output will be produced.

B,C, and D

Which class does not contain a method for checking whether a file exists? (select all that apply) Select one or more: A. File B. Scanner C. PrintWriter D. System

B,C, and D

Which of the classes below can not append or update a file? (select all that apply) Select one or more: A. RandomAccessFile B. OutputStream C. DataOutputStream D. File

B,C, and D

Which of the following are not techniques for connecting multiple streams in a class hierarchy (e.g., to connect a file with a stream and add buffering)? (select all that apply) Select one or more: A. stream layering B. stream concatenation C. stream addition D. stream connecting

B,C, and D

A sequence of bytes that flow into or out of a program is called a __________. Select one: A. channel B. path C. stream D. storage device

C

After the following program is finished, how many bytes are written to the file myFile.dat? import java.io.*; public class MyProgram{public static void main( String [] args ) throws IOException{DataOutputStream output = new DataOutputStream( new FileOutputStream( "myFile.dat" );output.writeInt( 1234 );output.writeDouble( 5678.3 );output.close();}} Select one: A. 4 bytes B. 8 bytes C. 12 bytes D. 16 bytes

C

An important benefit of inheritance is that it enables programmers to __________ code. Select one: A. duplicate B. modify C. reuse D. access

C

Consider the code below: public interface MyInterface{ int myMethod(); final int MAX = 10;} public class MyClass implements MyInterface{ public int myMethod() { return MAX; }} public class MyProgram{ public static void main( String [] args ) { MyClass obj = new MyClass(); System.out.println( obj.myMethod() ); }} Which of the following statements is true? I. The program will not compile because the visibility of myMethod() is not explicitly specified. II. The program will not compile because MAX has protected visibility. III. The program will compile and run correctly. Select one: A. I only B. II only C. III only D. I and II only

C

Members of a base class that have __________ visibility are accessible by subclasses. Select one: A. static B. private C. protected D. final

C

Objects of class Person are stored in a file. The following code segment reads objects from the file and displays them on the standard output device by calling the display( Person p ) method. Which of the choices for invoking the display() method is correct? ...Object obj = null;while( ( obj = in.readObject() ) != null )display( ??? ); // specify how display() should be called... Select one: A. display( obj ); B. display( Person obj ); C. display( (Person) obj ); D. display( (Serializable) obj );

C

The DataOutputStream class can be used to write to __________ files. Select one: A. primitive B. text C. binary D. character

C

The relationship between an interface and a class that implements it is __________. Select one: A. composition B. aggregation C. inheritance D. containment

C

To append data to an existing file, which of the following can be used to construct a FileOutputStream for the file out.dat? Select one: A. new FileOutputStream( "out.dat" ) B. new FileOutputStream( "out.dat", false ) C. new FileOutputStream( "out.dat", true ) D. new FileOutputStream( true, "out.dat" )

C

What is the output of the following code? public class MyProgram{ public static void main( String [] args ) { Beta myObj = new Beta( 10, 20 ); myObj.display(); }} public class Alpha{ private int a; public Alpha( int x ) { a = x; } public int getData() { return a; }} public class Beta extends Alpha{ private int b; public Beta( int ad, int bd ) { super(); b = bd;} public void display() { System.out.println( "a = " + getData() + " b = " + b ); }} Select one: A. a = 10 b = 20 B. a = 20 b = 10 C. The program will not compile D. The program will compile, but there will be a runtime error

C

What is the output of the following program? public class MyProgram{public static void main( String [] args ){System.out.println( "Hello World" );try{System.out.println( "Goodbye World" );}finally{System.out.println( "Finally" );} }} Select one: A. Hello World B. Hello WorldFinally C. Hello World Goodbye World Finally D. Finally

C

What is the output of the following program? public static void main( String [] args ){ try { int i = 0; int x = 10 / i; System.out.print( "Alpha " ); } catch( RuntimeException e ) { System.out.print( "Beta " ); } catch( Exception e ) { System.out.print( "Gamma " ); } finally { System.out.print( "Delta " ); }} Select one: A. Alpha Beta Gamma Delta B. Alpha Beta Gamma C. Beta Delta D. Alpha Gamma Delta Feedback

C

Which of the following can be used to create an input object for file myFile.txt? Select one: A. new System.in( "myFile.txt" ) B. new Scanner( myFile.txt ) C. new Scanner( new File( "myFile.txt" ) ) D. new Scanner( File( "myFile.txt" ) )

C

Which of the following is an abstract base class for writing output? Select one: A. FileOutputStream B. DataOutputStream C. OutputStream D. BinaryOutputStream

C

Which of the following statements is true? Select one: A. Base classes are more specialized than their subclasses. B. A subclass is usually more general than its parent class. C. "class A extends B" means that A is a subclass of B. D. "class A extends B" means that B is a subclass of A.

C

Which of these interface definitions will compile correctly? interface Alpha {public final int C1 = 19;public final static int C2 = 22;double C3 = 33.3;}interface Beta{ double CB1 = 1.29;double CB2 = 8.88;} Select one: A. Alpha only B. Beta only C. Both will compile correctly D. Neither will compile correctly

C

Consider the code below: public abstract class Animal{ public abstract void draw();} public class Cat extends Animal{ private String name = "Tiger"; public void draw() { System.out.println( "Drawing cat named " + name ); }} public class Frog extends Animal{ private String name = "Kermit"; public void draw() { System.out.println( "Printing frog named " + name ); }} public class MyProgram{ public static void main( String [] args ) { Animal [] myAnimals = { new Frog(), new Cat() }; myAnimals[0].draw(); myAnimals[1].draw(); }} Which of the following statements is true? I. The code will not compile and run because Animal is an abstract class. II. The code will compile and run correctly. III. The program attempts to use polymorphic behavior. Select one: A. I only B. II only C. III only D. II and III only

D

Consider the statements below: I. abstract class Person { ... } II. class Student extends Person { ... } III. class Student extends GraduateStudent { ... } Which of the following make design sense? Select one: A. I only B. II only C. III only D. I and II only E. I and III only

D

Consider the statements below: I. abstract class Vehicle { ... } II. class Boat extends Vehicle { ... } III. class Tugboat extends Sailboat { ... } Which of the following make design sense? Select one: A. I only B. II only C. III only D. I and II only E. I and III only

D

In the program below, what happens if the file test.dat does not exist when the program is run? import java.io.*; public class MyProgram{public static void main( String [] args ){try{RandomAccessFile raf = new RandomAccessFile( "test.dat", "r" );int x = raf.readInt(); }catch ( IOException e ){System.out.println( "IO Exception occurred" );} } } Select one: A. The program does not compile because raf is not created correctly. B. The program does not compile because readInt() is not a method of RandomAccessFile. C. The program compiles, and its output is "IO Exception occurred". D. The program compiles and runs fine, and no output is displayed.

D

In the program below, what happens if the file test.dat does not exist when the program is run? import java.io.*; public class MyProgram{public static void main( String [] args ){try{RandomAccessFile raf = new RandomAccessFile( "test.dat", "rw" );raf.writeInt( 123 ); }catch ( IOException e ){System.out.println( "IO Exception occurred" );} } } Select one: A. The program does not compile because raf is not created correctly. B. The program does not compile because readInt() is not a method of RandomAccessFile. C. The program compiles, and its output is "IO Exception occurred". D. The program compiles and runs fine, and no output is displayed.

D

What exception type does the following program throw? public class MyProgram{public static void main( String [] args ){MyClass myObject = null;System.out.println( myObject.toString() );}} public class MyClass{private int x;} Select one: A. ArithmeticException B. ArrayIndexOutOfBoundsException C. MethodNotFoundException D. NullPointerException

D

What exception type does the following program throw? public class MyProgram{public static void main( String [] args ){Object myObject = null;System.out.println( myObject.toString() );}} Select one: A. ArithmeticException B. ArrayIndexOutOfBoundsException C. MethodNotFoundException D. NullPointerException

D

What is the output of the following program? public class MyProgram{public static void main( String [] args ){try{System.out.println( "Goodbye World" );}finally{System.out.println( "Finally" );}System.out.println( "Hello World" ); }} Select one: A. Hello World B. Goodbye WorldFinally C. FinallyHello World D. Goodbye WorldFinallyHello World

D

Which of the following interface definitions will compile correctly? interface InterfaceA{public abstract void funcA();void funcB();private int myMethod();double CONSTA = 111;}interface InterfaceB{protected int CONSTB = 10;void func1();void func2();void func3();} Select one: A. InterfaceA only B. InterfaceB only C. Both interfaces will compile. D. Neither of the interfaces will compile.

D

Which of the following is a correct interface definition? Select one: A. interface A { void myMethod() { }; } B. abstract interface A { myMethod(); } C. abstract interface A { abstract void myMethod() { }; } D. interface A { void myMethod(); }

D

Which of the following is an abstract base class for reading binary input? Select one: A. FileInputStream B. BinaryInputStream C. DataInputStream D. InputStream

D

Which of the following statements is true for the code below? public class MyProgram{public static void main( String [] args ){A myObj1 = new A();B myObj2 = new B();System.out.println( myObj2.myFunc() );}} public class A{private int a; public int myFunc() { return a; }} public class B extends A{private int b; private int myFunc() { return b; }} Select one: A. The program output is 0 B. The code will not compile because class A and class B have no defined constructors C. The code will compile, but there will be a runtime error D. The code will not compile for reasons other than the above

D

Which of the following statements is true for the code below? public class MyProgram{public static void main( String [] args ){B myObj = new B();myObj.displayData();}} public class A{private int a;public A( int x ) { a = x; }public int getA() { return a; }} public class B extends A{private int b;public void displayData(){System.out.println( "a = " + getA() + " b = " + b );}} Select one: A. The program output is a = 0 b = 0 B. The program will compile, but a runtime error will occur because a and b are not initialized C. The program will not compile because no constructors are defined for class A and class B D. The program will not compile for reasons other than specified above

D

Which of the following statements is true for the code below? public class MyProgram{public static void main( String [] args ){B myObj = new B();myObj.myMethod( 5 );System.out.println( myObj.i );}} public class A{public int i;public void myMethod( int x ) { i = x; }} public class B extends A{public void myMethod( String s ) { }} Select one: A. The program has a compilation error because myMethod is overridden with a different signature in class B. B. The program has a compilation error because myObj.myMethod(5) cannot be invoked since myMethod is hidden in class B. C. The program has a runtime error because myObj.i is not legal. D. The method myMethod is not overridden in class B. Class B inherits myMethod from class A and defines an overloaded method called myMethod.

D

Which of the following statements is true for the code below? public class MyProgram{public static void main( String [] args ){B myObj = new B();}} public class A{protected int i = 7;public A() { setData( 20 ); System.out.println( "i from class A is " + i ); }public void setData( int d ) { i = 2 * d; }} public class B extends A{public B() { }public void setData( int d ) { i = 3 * d; }} Select one: A. The class A constructor is not called. B. The class A constructor is called and i from class A is 7 is displayed. C. The class A constructor is called and i from class A is 40 is displayed. D. The class A constructor is called and i from class A is 60 is displayed.

D

Which of the following statements is true? Select one: A. When an object is casted, it references an object of its own type. B. Casting an object that is lower in an inheritance hierarchy to an object that is higher in the hierarchy is called down-casting. C. Implementing polymorphic behavior involves up-casting. D. A parent class object can always store a reference to an object defined in one of its subclasses.

D

Which of the the following statements is true? Select one: A. It is mandatory that a program be able to recover from all exceptions that may be thrown by Java. B. You must always use a finally block when dealing with exception handling. C. A method can contain only a single try block. D. Programmers may define their own customized exception types.

D


संबंधित स्टडी सेट्स

Praxis 5622 Combined Sets 2: Classroom Management, Assessment, Diverse Learners, Special Education

View Set

SCM: Ch. 5 - Sourcing Materials and Services

View Set

Chapter 5 Adaptations to Anaerobic Training Programs

View Set