Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CS 391 - Advanced Programming in Java Autumn 2006 Quiz 2 Marks: 15 Time: 10 min. Roll Number: ______________ Date: 21/09/06 Fill in the blank spaces: [6] 1. ________________ clause is used to close resources that are opened and need to be closed during exception handling. 2. ____________________ exceptions must be caught or declared in a throws clause. 3. If we want to create a checked custom exception we need to inherit it from the ___________________ class. 4. ___________________ is a special java type which defines a set of method prototypes, but does not provide the implementation for the prototypes. 5. How do you call a function called ‘myFunction’ which is defined in a parent class from child class? ________________________ 6. Interfaces imply what kind of a relationship? _____________________________ (e.g. Inheritance is “Is-A” relationship) Encircle True or False: [4] 1. Abstract classes can have methods that are fully implemented. True / False 2. An abstract class can be instantiated. True / False 3. We can define static final constants in an Interface. True / False 4. Classes inherit from classes (single), interfaces inherit from interfaces (can be multiple) and classes implement interfaces (can be multiple) True / False Write the output for the following program segments? public interface Animal [3] { public void speak(); } class Lion implements Animal class Cat implements Animal { { public void speak() public void speak() { { System.out.println("roar"); System.out.println("meow"); } } } } public class Test { public static void main(String args[]) { Animal a; Lion l = new Lion(); l.speak(); a =l; a.speak(); a=new Cat(); a.speak(); } } Output: _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ public class ExceptionTest { public static void main(String arg[]) { try { System.out.println("Line 1"); throw (new Exception()); } catch(Exception e) { System.out.println("Line 2"); System.exit(0); } finally { System.out.println("Line 3"); } } } [2] Output: _________________________________________________________________ _________________________________________________________________