• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain Certpal Question

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • 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
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
So stupid I am...just missed the definition of the method getInteger()




Thanks for replying......
 
Ramesh Pramuditha Rathnayake
Ranch Hand
Posts: 178
2
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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..!
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic