click below
click below
Normal Size Small Size show me how
OOPf4
formative of hell
| Question | Answer |
|---|---|
| Unfortunately, polymorphic programs make it difficult to add new capabilities to a system. | false |
| Say that the situation is the same as in question 7. Which of the following array declarations is correct for an array that is expected to hold up to 10 objects of types Rat, Mouse, and PocketMouse? | Rodent[] array = new Rodent[10]; |
| All methods in a final class must be explicitly declared final. | false |
| Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically | true |
| If same message is passed to objects of several different classes and all of those can respond in a different way, what is this feature called? | polymorphism |
| Using higher degree of abstraction __________ | can be safer |
| In terms of stream and files ____________ | Abstraction is called a stream and device is called a file |
| 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"); } } | All classes compile |
| What is polymorphism in Java? | It is when a single variable is used with several different types of related objects at different places in a program. |
| There can be a try block without catch block but vice versa is not possible. | true |
| A method must do either of two things with a checked exception. What are those two things? | (1) Handle the exception in a catch{} block, or (2) throw the exception to the method that called this method. |
| Which are the two blocks that are used to check error and handle the error? | Try and catch |
| 20/20 | |
| Casting superclass references to subclass references is known as downcasting. | true? |
| Polymorphism is a feature of object oriented programming. | true |
| 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? |
| Which problem may arise if we use abstract class functions for polymorphism? | All the derived classes must implement the undefined functions? |
| The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes | false |
| Which of the following classes fail to compile? class X { } abstract class Y { } abstract class Z { abstract void method(); } | All classes compile? |
| What is an advantage of polymorphism? Group of answer choices | The same program logic can be used with objects of several related types. |
| Which among the following is not a level of abstraction? | View level? |
| Higher the level of abstraction, higher are the details. | False? |
| Which class is used to handle the input and output exceptions? | IOExceptions |
| Which of the following ways can be used to handle exceptions? X: By wrapping the desired code in a try block followed by a catch block to catch the exceptions. Y: List the desired exceptions in the throws clause of the method and let the caller shit | Both X and Y |
| An exception may arise when _______________ | Input given is invalid? |
| If the Java program is using assertions, it must be run with -ea or -enableassertions switches. | False |
| 19/20 | |
| Encapsulation is supported by ___________ | Classes? |
| Which among the following is the language which supports classes but not polymorphism? | Ada |
| Which among the following is not true for polymorphism? | Increases overhead of function definition always? |
| Objects of abstract superclasses can be instantiated. | false |
| What is an abstract method? | An abstract method is one without a body that is declared with? the reserved word abstract. |
| Which of the following is FALSE about abstract classes in Java | A class can inherit from multiple abstract classes.? |
| Can an abstract parent class have non-abstract children? | Yes--an abstract parent can have both abstract and non-abstract children.? |
| 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"); } } | All classes compile |
| Abstraction can apply to ____________ | Control and data |
| To catch the exceptions ___________________ | An object must be created to catch the exception |
| You are writing a program to check people into a hotel. People over 65 get a 10% discount. How would you write the program? | Normal if-else programming logic will be used.? |
| How many catch blocks can a single try block can have? | As many as required |
| 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. |
| Program throws ___________ if assert statement fails. | java.lang.AssertionError |
| 18/20 | |
| Which among the following best describes polymorphism? | It is the ability for a message/data to be processed in more than one form |
| Examine the following code: String str = "Hot Java"; boolean switch = str instanceof String; What value is placed in switch? | true ? The instanceof operator checks whether an object is an instance of a specific class. str is a String object, so str instanceof String evaluates to 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 ){ . . . .}? yung signature ang tinitignan is name and parameter list type and order |
| Here is an abstract method defined in the parent: public abstract int sumUp ( int[] arr ); Which of the following is required in a non-abstract child? | public int sumUp ( long[] arr ) { . . . }? |
| 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? | Operator overloading only? |
| If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used? | Using public member functions to access and manipulate the data members |
| 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"); } } | Z? |
| Which of the following classes fail to compile? abstract class X { abstract void method(); } abstract class Y extends X { void Method() { } } class Z extends X { void method() { } } | All classes compile? |
| Which is the universal exception handler class? | Exceptions? |
| What are two exception classes in hierarchy of java exceptions class? | Runtime exceptions and other exceptions? |
| 18/20 | |
| Polymorphism is possible in JAVA language. | True? |
| class X { } abstract class Y { } class Z { abstract void method(); } | Z? |
| Can an abstract class define both abstract methods and non-abstract methods? | Yes--the child classes inherit both. |
| Which among the following can be viewed as combination of abstraction of data and code. | Class? |
| Which of these is a super class of all errors and exceptions in the Java language? | Throwable? |
| Which among the following is not a method of Throwable class? | public Char toString()? |
| Say that methodA calls methodB, and methodB calls methodC. MethodC might throw a NumberFormatException. Can the program be written so that methodA handles the exception? | Yes, if the headers for methodC and methodB say ...throws NumberFormatException? |
| Which of the following statements is true? | It is sometimes good practice to throw an AssertionError explicitly.? |
| Which of the following statements is true? | It is sometimes good practice to throw an AssertionError explicitly.? |
| 19/20 | |
| Which one is runtime polymorphism? | option2: MethodOverriding? |
| What is the name of the class that is the ancestor to every other class in Java? | object? |
| If a class leaves one method in an interface undeclared, the class is implicitly declared by Java as an abstract class. | true? |
| The ability to define more than one function with the same name is called? | Polymorphism |
| class X { abstract void method(); } abstract class Y extends X { } class Z extends Y { void method() { } } | x? |
| Which of the following is correct? Group of answer choices All classes of Exception extend from Throwable. All classes of Error extend from Exception. All classes of Exception extend from Error. All classes of Throwable extend from Exception | All classes of Exception extend from Throwable.? |
| If a file that needs to be opened is not found in the target location then _____________ | Exception will be produced? |
| 18/20 |