Categories

Main
Database
Java
Microsoft.NET
Adabas
DB2
Informix
Microsoft SQL Server
MySQL
Oracle
Pervasive.SQL
PostgreSQL
Sybase
Other
ASP
ColdFusion
Crystal Reports
Delphi, C etc
JAVA
Microsoft.NET
Perl and the DBI
PHP
ANSI SQL
Unix Shell Scripts
Visual Basic
XML & XSLT
Corel Paradox
FileMaker
Microsoft Access
Microsoft Excel
Other PC Databases
Applications & Tools
Database Concepts & Design
EJB programming & troubleshooting
EJB design
General J2EE
XML & Web services
Web tier: servlets, JSP, Web frameworks
Performance and scalability
Industry news
TSS feedback
Mobicents Contributors
Mobicents Users
JSLEE Resource Adaptor Types
Planning JavaOne 2008
Sun Tech Days
Other Java conferences
Binary Web Services and XML
Metro and JAXB
GlassFish
GlassFish Plugins
Project jMaki
GlassFish WebTier
Mural
Java Development Tools
Java WS & XML Community News
JAXP
Java SE
6uN Early Access
Java Quick Starter
Java SE Snapshots: Project Feedback
JCK Forum
Feedback and Suggestions
JDK Distros
JDK Open Source
General JSR Discussion
JCP 2.6
JXTA Community Forum
ME Interest
ME Cool Apps
ME General Help
ME Feedback & Suggestions
ME Application Developer Interest
Blu-ray Disc Java
ME Developer Days
Squawk
Mobile Developer Alliance
OpenCable
LWUIT
JavaFX Script Language Discussion
OpenJFX General Discussion
Scene Graph
General Performance Discussion
Your Java Career
NetBeans 6.0
Servlets
JSP
JSF
Portals and Portlets
EJB and Other Java EE Technologies
Distributed Java
Object Relational Mapping
JDBC
Web Services
Swing / AWT / SWT / JFace
JNLP and Web Start
Java Micro Edition
Sockets and Internet Protocols
Threads and Synchronization
Performance
Applets
I/O and Streams
Other Java APIs
Game Development
Java in General (beginner)
Java in General (intermediate)
Java in General (advanced)
Programmer Certification (SCJP)
Developer Certification (SCJD)
Associate Certification (SCJA)
Web Component Certification (SCWCD)
EJB Certification (SCBCD)
Mobile Application Certification (SCMAD)
Architect Certification (SCEA)
Web Services Certification (SCDJWS)
XML Certification
Product and Other Certifications
Mock Exam Errata
Sun Certification Results
Authors' Corral
Book Reviews
Events
Bunkhouse Porch
Teachers' Lounge
Testing
OO, Patterns, UML and Refactoring
IDEs, Version Control and other tools
Ant, Maven and Other Build Tools
Linux / UNIX
Mac OS
HTML and JavaScript
XML and Related Technologies
Agile and Other Processes
General Computing
Security
Groovy
Scala
Other Languages
Struts
Application Frameworks
Other Open Source Projects
BEA/Weblogic
IBM/Websphere
Oracle/OAS
Apache/Tomcat
JBoss
Other Java Products and Servers
JavaRanch
Cattle Drive (java college)
Moderators Only
Trash Can
Jobs Offered
Jobs Wanted
Jobs Discussion
Meaningless Drivel
Programming Diversions
Blatant Advertising
Java Announcements
New To Java
Advanced Java
Java Applets
Networking
Threads and Synchronization
Java 2D
AWT / Swing
SWT / JFace
CLDC and MIDP
CDC and Personal Profile
Sun Java Wireless Toolkit
Enterprise JavaBeans
JavaServer Pages (JSP) and JSTL
Java Servlet
JavaServer Faces
Web Frameworks
Database
XML
Lucene
NetBeans
Eclipse
IntelliJ IDEA
JCreator
Other IDEs
Java Tutorials
Java Tips
Jobs Discussion
Jobs Offered
Jobs Wanted
Professional Certification
Forum Lobby
Java Blogs
Introductions
Reviews / Advertising
Suggestions & Feedback

Resources

Java Database
Linux
Coding
Mobile
Hardware
Software Development
Software Development
iOS,OS X
iOS,OS X
ORACLE
IBM DEVELOPER
IBM DEVELOPER
MSDN
MSDN


Tags

Programmer Certification (SCJP)

Programmer Certification (SCJP) Discussion of the Sun Certified Java Programmer Exam.

Exception handling


Question on exceptions..Imagine there are two exception classes called Exception1 and Exception2 that descend from the Exception class. Given these two class definitions:class First {void test()  throws Exception1, Exception2 { . . . }}class Second extends First {void test()  { . . . }}Create a class called Third that extends Second and defines a test()  method. What exceptions can Thirds test()  method throw?Select all valid answers.a.	Exception1b.	Exception2c.	no checked exceptionsd.	any exceptions declared in the throws clause of the Thirds test()  method.I think the answer is a,b,c.. is that right ?Another question...Assuming a method contains code which may raise an Exception (but not a RuntimeException)  what is the correct way for a method to indicate that it does not handle that exception:A.	throw ExceptionB.	throws ExceptionC.	new ExceptionD.	Don't need to specify anythingi think it is B since exception is uncertain.. or is it C? when is new Exception thrown ?Thanks in advance

   
   

 
   
      I think, answer on first question is C, and on second - B--------------------SCJP - 98%SCWCD - ...

   
   

   
   
      For the first question, the correct answer is c, because an object of the subclass ("Third") can be used instead an object of the parent class ("Second"). If the overloaded method would throw a new checked exception, this might not be handled in the code written for the test() method of the parent class, where no exception handling is necessary at all.For the second question, I also agree on that the correct answer is b; an exception of class Exception (note the capitalization in the question...) is a checked exception, so it must be declared to be thrown, al long as it is not handled locally. If 'only' a RuntimeException (or a subclass) would be thrown, there would be no need to declare it.

   
   

   
   
      Hi for the first question, the options a,b,c are all correct. check the following code, it compiles without any errors...class a1 {void sample () throws RuntimeException{}}class b1 extends a1{void sample(){}}class c1 extends b1{void sample() throws RuntimeException {}}public class ExceptionChecking {public static void main(String[] args) {}}

   
   

 
   
      Hi Santosh,A subclass can only throw a subset ofcheckedexceptions. The code snippet that you provided would fail to compile if RuntimeException was replaced by a checked exception, say SQLExceptionCheersArvind


Related Links

JQ+ swith question
Ready?
what exactly System.in is ?
JDK 1.2 or 1.3 for SCJP
Passed the exam
Need Advice: what should I read first?
Thread Safety!!!!
What will be the output....Please explain
Output or Compilation error? Surprising!
please,I want project information,on web server
SCJP2 from Oracle Platform n SUN platform whats the diff
Who can explain why java has not the keyword ""
what is format for fill in the blanks questions
JDK1.2 or 1.3 for SCJP ?
Garbge collector !!!
Overriding in interface