click below
click below
Normal Size Small Size show me how
CCS0070 FINALS
| Question | Answer |
|---|---|
| Encapsulation is supported by ___________ Methods Objects None of the above Classes | Classes |
| [T/F] An interface is typically used in place of an abstract class when there is no default implementation to inherit. | True |
| What is a method's signature? A.) a method is the name of the method the type of its return value. B.)a method is the name of the method, its parameter list, and its return type. | The signature of a method is the name of the method, its parameter list, and its return type. |
| Which among the following is the language which supports classes but not polymorphism? C++ Java SmallTalk Ada | Ada |
| Here is a method definition: int compute( a int, y double ){ . . . .} Which of the following has a different signature? int compute( a int, y int ){ . . . .} int compute( sum int, value double ){ . . . .} | int compute( a int, y double ) { ... } |
| If the processor represents all the functioning of phone, display shows the display only, and the phone is represented as a whole. Which among the following have highest level of abstraction? Camera Motherboard Phone Display | Phone |
| Which of the following classes fail to compile? class X { } abstract class Y { } abstract class Z { abstract void method(); } All classes compile X, Y Y Y, Z X, Y, Z | All classes compile |
| Using higher degree of abstraction __________ May get unsafe Can increase vulnerability Can be safer May reduce readability | Can be safer |
| Which among the following can be viewed as combination of abstraction of data and code. Interfaces Inheritance Object Class | Object |
| What is an exception? Problem arising during compile time Problem in syntax Problem arising during runtime Problem in IDE | Problem arising during runtime |
| Which symbol should be used to separate the type of exception handler classes in a single catch block? , ? – | | | |
| The built-in base class in Java, which is used to handle all exceptions is Raise Throwable Error Exception | Throwable |
| [T / F] Private getter() and setter() methods should not use assertions to verify arguments | True |
| [T / F] The programmer can choose to execute a return statement or to throw an exception if an assertion fails. | True |
| [T / F] The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes | False |
| [T / F] Examine the following code: String str = "Hot Java"; boolean switch = str instanceof String; What value is placed in switch? | True |
| The ability to define more than one function with the same name is called? Encapsulation Inheritance Abstraction Polymorphism | Polymorphism |
| [T / F] An abstract class cannot have instance data and non-abstract methods. | False |
| [T / F] If a subclass reference is assigned to a superclass variable, the variable must be cast back to the subclass before any subclass methods can be called with it. | True |
| [T / F] Higher the level of abstraction, higher are the details. | False |
| In order for the following code to be correct, what must be the type of the reference variable card? _________ card; card = new Valentine( "Joe", 14 ) ; card.greeting(); card = new Holiday( "Bob" ) ; card.greeting(); | Card |
| Abstraction can apply to ____________ Only control Classes Only data Control and data | Control and data |
| What is an abstract class? An abstract class is any parent class with more than one child class. An abstract class is class which cannot be instantiated. | An abstract class is class which cannot be instantiated. |
| How many catch blocks can a single try block can have? Maximum 127 Only 2 Only 1 As many as required | As many as required |
| Which class is used to handle the input and output exceptions? IOExceptions ExceptionsIO InputOutputExceptions InputOutput | IOExceptions |
| MethodX might encounter an IOException or an AWTException, but handles neither. How should the header for methodX be written? | public void methodX() throws IOException, AWTException { // Method implementation } |
| [T / F] It is not required for the caller method to catch or re-throw the checked exception. | False |
| [T / F] Assertion checking is typically enabled when a program is deployed. | False |
| [T / F] It is never appropriate to write code to handle failure of an assert statement. | False |
| [T / F] It is never appropriate to write code to handle failure of an assert statement. | True |
| [T / F] Assertion checking is typically enabled during program development and testing. | True |
| [T / F] Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis. | True |
| [T / F] Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis. | False |
| [T / F] An abstract class declares a common interface for the various members of a class hierarchy. All classes in the hierarchy can use this same set of methods through polymorphism. | True |
| Here is a method definition: int compute( a int, y double ){ . . . .} Which of the following has a different signature? int compute( a int, y int ){ . . . .} int compute( sum int, value double ){ . . . .} | int compute( a int, y int ){ . . . .} |
| Which among the following can't be used for polymorphism? Member functions overloading Static member functions Predefined operator overloading Constructor overloading | Static member functions |
| What must be true if a child of an abstract parent class does not override all of the parent's abstract methods? The parent class is in error. This is always an error. The child class itself must be declared to be abstract. | The child class itself must be declared to be abstract. |
| Can an abstract class define both abstract methods and non-abstract methods? No--it must have all abstract methods. No--it must have all one or the other. Yes--the child classes inherit both. | Yes--the child classes inherit both. |
| Which of the following classes fail to compile? class X { } abstract class Y { } abstract class Z { abstract void method(); } a.)X, Y, Z b.)Y c.)All classes compile d.)Y, Z e.)X, Y | c.)All classes compile |
| [T / F] if a class defines an abstract method the class itself must be abstract. | True |
| What determines what method is run in the following: Card crd = new BirthDay("Lucinda", 42); crd.greeting(); The type of the object or the type of the reference variable? The type of the object. The type of the reference variable. | The type of the object. |
| The built-in base class in Java, which is used to handle all exceptions is Exception Raise Throwable Error | Throwable |
| What is an exception? Problem arising during runtime Problem arising during compile time Problem in IDE Problem in syntax | Problem arising during runtime |
| [T / F] Objects of abstract superclasses can be instantiated. | False |
| Which type of function among the following shows polymorphism? Inline function Virtual function Class member functions Undefined functions | Virtual function |
| [T / F] If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as abstract using 'abstract' keyword | False |
| Which of the following classes fail to compile? abstract class X { abstract void method(); } class Y extends X { } class Z extends Y { void method() { System.out.println("Class Z"); } } Y, Z Y Z X, Y, Z | Y |
| What is an advantage of polymorphism Polymorphism is a dangerous aspect of inheritance and should be avoided. Variables can be re-used in order to save memory. The same program logic can be used with objects of several related types. | The same program logic can be used with objects of several related types. |
| Which of the following classes fail to compile? abstract class X { abstract void method(); } abstract class Y extends X { } class Z extends Y { void Method() { System.out.println("Class Z"); } } X, Y X, Y, Z Y Z | Z |
| An exception may arise when _______________ Input is fixed Input given is invalid Input is valid Input is some constant value of program | Input is valid |
| What is an exception? Problem in IDE Problem arising during compile time Problem arising during runtime Problem in syntax | Problem arising during runtime |
| [T / F] The programmer can choose to execute a return statement or to throw an exception if an assertion fails. | True |
| [T / F] Conditional compilation is used to allow tested classes to run at full speed | False |
| [T / F] Assertions are appropriate for checking the validity of arguments in a method. | False |
| [T / F] Assertions can be enabled or disabled on a class-by-class basis. | False |
| [T / F] If the Java program is using assertions, it must be run with -ea or -enableassertions switches. | False |
| Which array declaration is correct that to hold up to 10 objects of types Rat, Mouse, and PocketMouse? A) Rodent rodents[10]; B) Rodent[] array = new Rodent[10]; C) Rodent rodents = new Rodent[10]; D) Rodent[] rodents; | Rodent[] array = new Rodent[10]; |
| [T / F] All methods in a final class must be explicitly declared final. | False |
| If 2 classes derive one base class and redefine a function of base class, also overload some operators inside class body. Among these two things of function and operator overloading, where is polymorphism used? | Function overloading only |
| [T / F] A method that is declared final cannot be overridden in a subclass. | True |
| What method of an Exception object prints a list of methods that were called before the exception was thrown? printStackTrace() printErrors() traceStack() getMessage() | printStackTrace() |
| Say that a method catches an IOException in a catch{} block. Is it possible for that block to do some processing and then throw the same exception to the caller? | Yes---as long as the method also has a throws clause for that exception. |
| What happens during execution if an negative value is used for an array index? A NumberFormatException is thrown. An IndexOutOfBoundsException is thrown. The first slot of the array is used. | An IndexOutOfBoundsException is thrown. |
| To catch the exceptions ___________________ An array should be created to catch all the exceptions An object must be created to catch the exception A variable should be created to catch the exception | An object must be created to catch the exception. |
| [T / F] It is sometimes good practice to throw an AssertionError explicitly. | True |
| The encapsulation is achieved by combining which ones into a class? Methods and Attribute None of the above Methods and Object Object and Attribute | Methods and Attribute |
| [T / F] If a class leaves one method in an interface undeclared, the class is implicitly declared by Java as an abstract class. | False |
| Which of the following is FALSE about abstract classes in Java A class can be made abstract without any abstract method Abstract classes can have constructors A class can inherit from multiple abstract classes. | A class can inherit from multiple abstract classes. |
| Encapsulation and abstraction differ as ____________ Can be used any way Hiding and hiding respectively Binding and Hiding respectively Hiding and Binding respectively | Hiding and Binding respectively |
| [T / F] There can be a try block without catch block but vice versa is not possible. | True |
| What happens during execution if an negative value is used for an array index? B) The array element at index 0 is accessed. C) The program throws an ArrayIndexOutOfBoundsException. D) The array index is automatically set to 0. | An IndexOutOfBoundsException is thrown. |
| [T / F] Running a java program with -ea switch will enable assertion in system classes. | False |
| Program throws ___________ if assert statement fails. java.lang.AssertError java.lang.AssertException java.lang.AssertionException java.lang.AssertionError | java.lang.AssertionError |