Quiz 2 Solution

Quiz 2 Solution - Try block (1): • The code that could...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Quiz 2 Marks: 15 Time: 10 min. Name : Solution Roll Number : ______________ Date: 5/9/2007 1. ___ Up __________ is implicit, while ____ Down ______ is explicit in Java. 2. public class Bird {…} public class Canary extneds Bird {. .} public class Driver { public static void main(String[] args) { Bird b = new Bird(); Canary c = b; } Is this code correct? Why? No. Down casting is explicit 3. long h = 100.0 True/ False 4. A parent class reference variable can be used to point True / False to any object of its decendance. 5. “Error” is represented as an object in Java, it should also be caught True/ False and handled. 6. Unchecked exceptions such as Runtime Exceptions, True / False do not require explicit handling. 7. Throwable/Exception encapsulates all kinds of exceptions Please turnover
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8. How are Java exceptions handled? Explain the purpose of each block briefly yet completely. (6 marks)
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Try block (1): • The code that could potentially generate an error is placed in this block Catch block (1): • Encapsulates that code responsible for error/exception handling Throw (1): • Manually throw exceptions that have been defined by the user, Alls partial processing of the error and throws back to the caller method Finally (2): • Always Executed • Opend resources are closed • Appears after the last catch block • Will not execute if Syste.exit(0) executes first Throws (1): • Throws the error for handling to caller • Throws clause at a class leve (caller class) 9. Is it possible to writemultiple catch blocks? If yes describe the most effective way of writing it. (2 marks) Yes it is. Write mst specific exception catch block first and end with the most general one. – Fail first approach....
View Full Document

This note was uploaded on 05/09/2010 for the course CS CS300 taught by Professor Abh during the Spring '10 term at lln.

Page1 / 2

Quiz 2 Solution - Try block (1): • The code that could...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online