You are on page 1of 5

NL NL O NP

b = g~ ~= n = J= m ~ = ~= ^

Search

Arithmetic Aptitude Data Interpretation Logical Reasoning Verbal Reasoning Non Verbal Reasoning General Knowledge Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles C Programming C++ Programming C# Programming Java Programming Microbiology Biochemistry Biotechnology Biochemical Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing Placement Papers Group Disucssion HR Interview Technical Interview Body Language Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing Aptitude Reasoning Verbal Ability GK Puzzles Programming Engineering Medical Interview Online Test

Java Programming :: Exceptions


@ : Home > Java Programming > Exceptions > Finding the output

1. What will be the output of the program?


pbi casFo ulc ls o { pbi sai vi mi(tig]ag) ulc ttc od anSrn[ rs { ty r { rtr; eun } fnly ial { Sse.u.rnl("ial") ytmotpitn Fnly ; } K ~ L~ ~J L K ~ L NL R

NL NL O NP }

b = g~ ~= n = J= m ~ = ~= ^ } }

A. Finally B. Compilation fails. C. The code runs with no output. D. An exception is thrown at runtime. Answer & Explanation Answer: Option A Explanation: If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances: 1. 2. 3. 4. An exception arising in the finally block itself. The death of the thread. The use of System.exit() Turning off the power to the CPU.

I suppose the last three could be classified as VM shutdown. View Answer Workspace Report Discuss in Forum 2. What will be the output of the program?
ty r { itx=0 n ; ity=5/x n ; } cth(xeto e ac Ecpin ) { Sse.u.rnl(Ecpin) ytmotpitn"xeto"; } cth(rtmtcxeto a) ac AiheiEcpin e { Sse.u.rnl( Aihei Ecpin) ytmotpitn" rtmtc xeto"; } Sse.u.rnl(fnse"; ytmotpitn"iihd)

A.finished C.Compilation fails. Answer & Explanation Answer: Option C Explanation:

B.Exception D.Arithmetic Exception

Compilation fails because ArithmeticException has already been caught. ArithmeticException is a subclass of java.lang.Exception, by time the ArithmeticException has been specified it has already been caught by the Exception class. If ArithmeticException appears before Exception, then the file will compile. When catching exceptions the more specific exceptions must be listed before the more general (the subclasses must be caught before the superclasses). View Answer Workspace Report Discuss in Forum 3. What will be the output of the program?
pbi casX ulc ls { pbi sai vi mi(tig[ ag) ulc ttc od anSrn ] rs { ty r { bdehd) aMto(; K ~ L~ ~J L K ~ L

OR L

NL NL O NP

b = g~ ~= n = J= m ~ = ~= ^ bdehd) aMto(; Sse.u.rn(A) ytmotpit""; } cth(xeto e) ac Ecpin x { Sse.u.rn(B) ytmotpit""; } fnly ial { Sse.u.rn(C) ytmotpit""; } Sse.u.rn(D) ytmotpit""; } pbi sai vi bdehd) ulc ttc od aMto( { trwnwErr) / Ln 2 * ho e ro(; * ie 2 / }
}

Ads by Google

Java Programming Learn Java Java Language

A. ABCD B. Compilation fails. C. C is printed before exiting with an error message. D. BC is printed before exiting with an error message. Answer & Explanation Answer: Option C Explanation: Error is thrown but not recognised line(22) because the only catch attempts to catch an Exception and Exception is not a superclass of Error. Therefore only the code in the finally statement can be run before exiting with a runtime error (Exception in thread "main" java.lang.Error). View Answer Workspace Report Discuss in Forum 4. What will be the output of the program?
pbi casX ulc ls { pbi sai vi mi(tig[ ag) ulc ttc od anSrn ] rs { ty r { bdehd) aMto(; Sse.u.rn(A) ytmotpit""; } cth(utmEcpine)/ Ln 1 * ac Rniexeto x * ie 0 / { Sse.u.rn(B) ytmotpit""; } cth(xeto e1 ac Ecpin x) { Sse.u.rn(C) ytmotpit""; } fnly ial { Sse.u.rn(D) ytmotpit""; } Sse.u.rn(E) ytmotpit""; } pbi sai vi bdehd) ulc ttc od aMto( { trwnwRniexeto(; ho e utmEcpin) } }

Exercise
Finding the output Pointing out the correct statements "I do not seek. I find." - Pablo Picasso

A.BD C.BDE Answer & Explanation Answer: Option C Explanation:


K ~ L~ ~J L K ~ L

B.BCD D.BCDE

PL R

NL NL O NP

b = g~ ~= n = J= m ~ = ~= ^

A Run time exception is thrown and caught in the catch statement on line 10. All the code after the finally statement is run because the exception has been caught. View Answer Workspace Report Discuss in Forum 5. What will be the output of the program?
pbi casREcp ulc ls Txet { pbi sai vi trwt( ulc ttc od hoi ) { Sse.u.rn(trwt"; ytmotpit"hoi ) trwnwRniexeto(; ho e utmEcpin) } pbi sai vi mi(tig[ ag) ulc ttc od anSrn ] rs { ty r { Sse.u.rn(hlo"; ytmotpit"el ) trwt) hoi(; } cth(xeto r ) ac Ecpin e { Sse.u.rn(cuh "; ytmotpit"agt ) } fnly ial { Sse.u.rn(fnly"; ytmotpit"ial ) } Sse.u.rnl(atr"; ytmotpitn"fe ) } }

A. hello throwit caught B. Compilation fails C. hello throwit RuntimeException caught after D. hello throwit caught finally after Answer & Explanation Answer: Option D Explanation: The main() method properly catches and handles the RuntimeException in the catch block, finally runs (as it always does), and then the code returns to normal. A, B and C are incorrect based on the program logic described above. Remember that properly handled exceptions do not cause the program to stop executing. View Answer Workspace Report Discuss in Forum 12Next >

The Rackspace Cloud


Rackspace.com/CloudServers

Scalable Servers in Minutes From $17 per Month. Get Your Server Now!

K ~ L~ ~J L K ~ L

QR L

NL NL O NP

b = g~ ~= n = J= m ~ = ~= ^

Ads by Google

Java Books

Java Program

Java Class

Java Problems

Read more: Exceptions - Pointing out the correct statements

2008-2012 by IndiaBIX T echnologies. All Rights Reserved | Copyright | T erms of Use & Privacy Policy Contact us: info@indiabix.com Bookmark to: Follow us on twitte r!

K ~ L~ ~J L K ~ L

RL R

You might also like