aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overridden method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overridden method" Watch "Overridden method" New topic
Author

Overridden method

Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi, Why Line6 is not valid override as per whizlabs mock exam

OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Because amethod in OtherTest is private.
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Thanks Stephan. This is from Whizlabs. Drag and Drop one of the following to Line # 8 and 10 so that given program compile and run
I. private int amethod(float i) {return 0;}
II. void amethod(int i) throws RuntimeException
I was thinking that answer would beBut, the answer is..Why ?
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

When we write method in the super class as private
and override using another method in subclass
it is not considered overriding at all as the private method is not accessible to the subclass
and
throwing RuntimeException by overriding method is allowed even if the superclass method does not throw exception

for this you have to check out rules for overriding neatly

happy preparation

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
Hi Prasad, Question doesn't refer anything about overriding..All it says is "compile & run"
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

Harikrishna Gorrepati wrote:Hi Prasad, Question doesn't refer anything about overriding..All it says is "compile & run"

I know friend
but read the rules for overriding and you will come to know what the problem is
happy preparation
Harikrishna Gorrepati
Ranch Hand

Joined: Sep 23, 2010
Posts: 422
I have gone through all rules. Anyways, overriding rule doesn't apply here in this code. Let me put it this way. Even if I use either 2nd or 3rd code snippet, It compiles & runs fine. Please advice.
swaraj gupta
Ranch Hand

Joined: Oct 22, 2010
Posts: 181

Harikrishna Gorrepati wrote:I have gone through all rules. Anyways, overriding rule doesn't apply here in this code. Let me put it this way. Even if I use either 2nd or 3rd code snippet, It compiles & runs fine. Please advice.


this time you are right harikrishna...
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

If I may, I have seen lots of really poor examples of code from WhizLabs. I don't know if they come highly recommended, but from all their code I've seen posted on this site, I would never even consider using them.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Stephan van Hulst wrote:If I may, I have seen lots of really poor examples of code from WhizLabs. I don't know if they come highly recommended, but from all their code I've seen posted on this site, I would never even consider using them.


Agree. In my opinion best would be the K&B Guide (CD)+ExamLab. On exam- there are tricky questions but few are at times easier.


Mohamed Sanaulla | My Blog
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Harikrishna Gorrepati wrote:I have gone through all rules. Anyways, overriding rule doesn't apply here in this code. Let me put it this way. Even if I use either 2nd or 3rd code snippet, It compiles & runs fine. Please advice.

Harikrishna Gorrepati, your answer also correct as like one they provided. But, they may want not to use the same code snaps for the two blanks.

Mu personal experience, don't use Whizlabs, I used it for my SCWCD preparation, but, not worth and making us confusing. There are many other useful mocks, like ExamLab. Use then as a study guide. This is my personal experience!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overridden method