• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Re :Results of mock test

 
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have few questions from mock test on exception handling . I tried it on the link
http://www.skillrack.com/mockscorereport.jsf?cid=701
but i am doubtful about the following answers . Please help me solve my doubts .
Question1

Options are:-
a. prints true as the Exception in the constructor prevents the Object being initialized
b. prints false

My doubt is how can a constructor throw an exception ?
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not read any article wherein the constructor can throw an exception
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In your code above, staticT, did get initialized. If you can see your code

This particular statement is checking whether null and staticT point towards the same object. They don't
thats why the output is false. If you amend your code and put a printout statement before the equality,
you will see staticT, does refer to an object.

Hope this helps,
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but my question remains can a constructor throw an exception
 
Benish Zaidi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes a constructor can throw an exception. There are many articles over google.
Just type, Can constructors throw an exception OR not? Actually, by throwing an
exception only from the constructor an object creation can be avoided. In your case
object t is not created.

Hope this helps,
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok thank you
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry i havent seen the code completly
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

santosh dhulipala wrote:i am sorry i havent seen the code completly


Like methods, Constructors, Instance Initialization blocks can throw exceptions.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic