The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A simple question about inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "A simple question about inheritance" Watch "A simple question about inheritance" New topic
Author

A simple question about inheritance

Michelle Chang
Greenhorn

Joined: Jan 22, 2010
Posts: 8



Choose three from the followings:
A. private void bar(int x){}
B. public void bar(int x){}
C. public int bar(String x){return 1;}
D. public Alpha bar(int x){}
E. public void bar(int x, int y){}
F. public int bar(int x){return x;}


The answer is BCE

My question is that is that true that because class Beta subclasses Alpha, Beta can either override or overload the methods that Alpha has? Why do D and F cannot fit into that block? Thanks.

This message was edited 1 time. Last update was at by Shifong Chang



Always speak up for stupid questions.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
You may want to check out the method signatures . . . Jim ... ...


BEE MBA PMP SCJP-6
Afzal Rehman
Ranch Hand

Joined: Dec 16, 2009
Posts: 35
Hi Michelle,

it's violating the rules of overriding , E is returning Alpha and superclass has void ,
and F is return int and superclass has void.

You need to keep on eye whenever you do override let say..

Must have the same argument List.
Must have the same return type . bu t in java 5 return type can be subclass this
is known as covariant return.
Must not have more restrictive modifier.
May have less less rectrivtive modifier.
etc. checkout..

SCJP 6.0
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13404

"Michelle Chang",

Please Quote Your Sources.

Thanks,
Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
appu sharma
Ranch Hand

Joined: Sep 20, 2009
Posts: 102

but in this case void so you cann't return anything..
let us suppose that if there is any method in base class like
then you can write this in your child class this
here Beta is covariant type of Alpha
vinit


It doesn't matter if you win by an inch or a mile; winning's winning.
 
 
subject: A simple question about inheritance
 
MyEclipse, The Clear Choice