• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Explain Certpal Question

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namaste Friends !!

Please explain me why the answer of following question is "This class is fine "
This is the Question-------------------

What is wrong with this class ?


Options are--

1.) There are no abstract methods

2.) This class is fine

3.) The semicolon at #1 should be removed if this class is to compile

4.) This class will get a runtime error if used

5.) There is a compile time error either at #2

6.) There is a compile time error either at #3
7.) There is a compile time error either at #4

I opted option 5 and 7, Certpal explained why option 5 is wrong and explanation given by it is "After Integer.MAX_VALUE the value of the integer is moved back in the negative range in a cyclic manner"

But it doesn't explained why option 7 is wrong and option 2 is correct .

Please explain me why option 2 is correct and opt 7 is not ??

Thanks
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vishal mishra wrote:Please explain me why option 2 is correct and opt 7 is not ??


Option 7 is wrong because there is nothing on that line that will cause a compiler error. What error were you expecting ?

Option 2 is correct because the class is fine. It's difficult to say anything else without you telling us why you think it is not fine.
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So stupid I am...just missed the definition of the method getInteger()




Thanks for replying......
 
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason is the same for 5.)

The return int variable is boxed into Integer class' object. Every object has toString() method.. Therefore no errors..!
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vishal mishra wrote:
1.) There are no abstract methods



Java Abstract Classes says -


Absolutely not. Indeed, a class can be abstract without any methods being abstract, although that's relatively rare (see Mark's comment below for an example). On the other hand, if a class has any abstract methods, then it must be declared abstract.



Regards,
Dan
 
reply
    Bookmark Topic Watch Topic
  • New Topic