*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question in JavaRanch Roundup 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 "Question in JavaRanch Roundup" Watch "Question in JavaRanch Roundup" New topic
Author

Question in JavaRanch Roundup

Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
Recently i tried the Roundup game. One of the question was:
Can an Abstract class be overidden?
1) True
2) False
My answer was false. But it says the other way, because abstract classes must be overidden.
If i am right, abstract methods are implemented in the suclass. They are not said to be overridden. Furthermore, overridden method can be called from overriding method using super.method() syntax. If a overridden method is abstract, how can we call them?
Is my view right?


Saravanan
Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
Please read the last post as:
Can an abstract method be overridden?
1) True
2) False
My answer was false. But it says the other way, because abstract methods must be overidden.
If i am right, abstract methods are implemented in the subclass. They are not said to be overridden. Furthermore, overridden method can be called from overriding method using super.method() syntax. If a overridden method is abstract, how can we call them?
Is my view right?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20582
    ∞

I guess your question falls to how we all interpret the word "override". We agree that the method in the sub class must have the same name, parameters and return value as the method in the super class to be called "overriding".
The difference seems to be if the method in the super class is abstract. You think that the method in the sub class is not "overriding" but is "implementing" the abstract method. I would say that it is doing both.
Unless someone has a quote from a JVM spec, I think this is a matter that is settled by vote.
If you read this, please add your vote and/or commentary.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Rich Wardwell
Ranch Hand

Joined: Jan 20, 2000
Posts: 33
I believe most of the materials (including the real exam) that I have seen would expect the behavior as is stated in the mock exam. Abstract classes are overridden, even though it has methods that have not been implemented.
So one vote for the question to stand as is.

------------------
Rich Wardwell
rcw3@levelpath.com
Sun Certified Programmer for the Java 2 Platform


<B>Rich Wardwell</B><BR> <A HREF="mailto:rcw3@levelpath.com" rel="nofollow">rcw3@levelpath.com</A> <BR>Sun Certified Programmer for the Java 2 Platform
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
My $0.02:



Short answer: "False. Classes cannot be overridden."



In my studies in Java, I have not come across anything saying that a class can be overridden, although I think I know what is meant by it. Only methods can be overridden. Of course we all know about the fact that abstract classes need to have all its abstract method implemented before an object can be instantiated.



So it all depends of whether we want to introduce new idiom that (I think) is not used in the exam, like "overriding abstract classes".



Maybe a "better" question amongst others would be:
"Must every class that is a descendant of an abstract class have all its abstract methods implemented?"



My $0.02


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20582
    ∞

Here is the actual question:
Can an abstract method be overridden?
And here is the current answer:
Yes An abstract method has no choice! It MUST be overridden.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Tony - note that Thandapani posted twice, and in the second post amended "abstract class" to "abstract method". So the question is intended to be about overriding abstract methods, not classes.
And back to the general discussion: add my vote to the "yes, an abstract method can be overridden" pile. The JLS itself uses the term "override" to describe what must be done to implement an abstract method. It even says that "An abstract class can override an abstract method by providing another abstract method declaration." Which obviously doesn't implement anything, but apparently it's still called an override.

"I'm not back." - Bill Harding, Twister
Thandapani Saravanan
Ranch Hand

Joined: Oct 17, 1999
Posts: 117
I think the part i still find uncomfortable is:
IT MUST BE OVERRIDDEN.
JLS uses the word "override" in two contexts:
1) When an abstract method is still abstract in the subclass (with minor modifications like change in throws clause).
2) When a concreate method becomes abstract in the subclass.
It says as soon as the subclass becomes concrete, then we have a implementation.
The following are the words used:
Method in Parent class Method in child We call
Abstract Abstract Overriding
Concrete Abstract Overriding
Abstract Concrete Implementing

If the specification is given and we write code, then the method is said to be implemented.
If either the specification or the implementation is changed then it is said to be overridden.

So,
Can an abstract method be overridden?
The answer: YES . It can either be implemented or overridden. .
Is it right?
BTW, I got 83, 90 and 93 in the round-up and i am taking the exam on Wednesday (02-02-2000). What do you guys think/advice?
Thanks in advance.

Sorry, if there is any formatting error.
[This message has been edited by Thandapani Saravanan (edited January 31, 2000).]
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20582
    ∞

They key to the game is that I don't have a lot real estate to work with, so the answer information must be brief.
I think the question is trying to trip up the test taker with the difference between abstract and final.
Maybe an explanation should be "Only final methods cannot be overridden" ??
Rich Wardwell
Ranch Hand

Joined: Jan 20, 2000
Posts: 33
You're right... Classes cannot be overridden - I shouldn't have used the word "class" in my post - should have used "method" - my bad. Even so, I believe the original question is good as is - maybe a little rewording to make it obvious that we are talking about a concrete implementation of an abstract class might make it a little more clear.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Thandapani-
I found a clearer part of the JLS here:
<blockquote>If a class declares an instance method, then the declaration of that method is said to override any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. Moreover, if the method declared in the class is not abstract, then the declaration of that method is said to implement any and all declarations of abstract methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code
in the class.
</blockquote>
From this, it appears that "implementing" is a subset of "overriding" - any time you are implementing, you are also overriding.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
COMMENT:
I'm "appalled" (just kidding) that they use the phrase "same signature" and not
"same signature and return type". We know that the compiler won't let us do otherwise of course, but there is still an "S" in "JLS" :-)
<PRE>
else {
I am missing something...
}
</PRE>
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
They do specify that later though, here. The way they set it up, the compiler can complain that your override is illegal because it changes the return type. (I.e. it is an override, but an illegal one.) If they didn't define things that way, the compiler would have to complain that your method declaration is illegal because it isn't a legal override, hide, or overload (which each have different requirements) and yet it's also not the first time the method name was used. I think the former is clearer.
[This message has been edited by Jim Yingst (edited January 31, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question in JavaRanch Roundup