Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Programmer Certification (OCPJP)
it should be more ambiguous then previous version.
wang hong gang
Greenhorn
Posts: 1
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello, everybody!
Please consider the following two version of code:
//--one is: //============================== public abstract class app implements i { public static void main(String[] args) { Sub obj1 = new Sub(); obj1.aMethod('c'); obj1.abstractMethod(); } } abstract class Super { void aMethod(char i) { System.out.println("this is a method from super"); } abstract void abstractMethod(); } class Sub extends Super { void aMethod(int c) { System.out.println("this is a method from sub"); } void abstractMethod() { System.out.println("this is abstract from sub"); } } //--the compiler print "reference to aMethod is ambiguous, //--both method aMethod(char) in Super and method aMethod(int) in Sub match" //--one is: //============================== public abstract class app implements i { public static void main(String[] args) { Sub obj1 = new Sub(); obj1.aMethod('c'); obj1.abstractMethod(); } } abstract class Super { void aMethod(char i) { System.out.println("this is a method from super"); } abstract void abstractMethod(); } class Sub { void aMethod(int c) { System.out.println("this is a method from sub"); } void aMethod(char i) { System.out.println("this is a method from super"); } void abstractMethod() { System.out.println("this is abstract from sub"); } } //--compiles correctly, surprising, it should be more ambiguous then previous version.
ps:
Pl. use the [ code ] and [ / code ] tags when posting source code. It really helps.
Thanks.
- satya
[ January 11, 2002: Message edited by: Madhav Lakkapragada ]
Jose Botella
Ranch Hand
Posts: 2120
posted 21 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
the declaration
void aMethod(char i) {
is the most specific method, read this post
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=24&t=014026
SCJP2. Please Indent your code using UBB Code
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
overriding method question and a super question.
question from Sun Guoqiao's homepage
overloading inherited method
///abstract///
this and super
More...