jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract methods" Watch "abstract methods" New topic
Author

abstract methods

saiprasad raut
Ranch Hand

Joined: Aug 29, 2003
Posts: 40
In dan chisholm mock exam i came across following question

Which of the following statements is true?

a. An abstract method can not be overridden by an abstract method.
b. An instance method that is not abstract can not be overridden by an abstract method.
c. An abstract method declaration can not include a throws clause.
d. The body of an abstract method is represented by a set of empty brackets.
e. None of the above.

The answer is e.

How can a and b is false?
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Is there an explanation given for the answers Dan provided? Perhaps he's looking at "overridden" in a slightly different way than I am.

I would say that A and B are correct answers, although A is rather pointless and B might be a questionable implementation and you'd have to back it up with good design decisions to ever do that in real life. However, for the sake of the SCJP exam, I'd say that both A and B are correct answers.


SCJP Tipline, etc.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
In the following code example, the abstract method B.m1 overrides the abstract method A.m1. You might want to override an abstract method with another abstract method if you want to use the overriding declaration as a place to put new documentation that would appear in a javadoc.

The abstract method B.m2 overrides A.m2. It is unlikely that you would find something like that in the first revision of a product. It is more likely that you would find something like that in a later revision that extends the product to do things that were previously not envisioned by the original design team.

The following code compiles without error.



Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
saiprasad raut
Ranch Hand

Joined: Aug 29, 2003
Posts: 40
Thanks Corey and Dan for the replies.

So for the exam, should i go ahead with the consideration that a and b is false?

By the example of Dan it seems so...

Saiprasad
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
No, no. A & B are true, not false.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by saiprasad raut:
Thanks Corey and Dan for the replies.

So for the exam, should i go ahead with the consideration that a and b is false?

By the example of Dan it seems so...

Saiprasad


Yes, the examples above show that an abstract method can override a method of a superclass. The overridden superclass method could be either concrete or could be abstract.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Of course unless the concrete method is final...
Compiler doesn't complain about this:

for this implementation of Test1:

but is rejected when Test1 is this:

Question remains what the point in overriding an concrete method with an abstract method actually is.
Given that derived classes should provide more (specific) behaviour compared to their parents it seems to go against OO principles to actually remove functionality by overriding a concrete method with an abstract one.


42
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by Jeroen Wenting:

...

Question remains what the point in overriding an concrete method with an abstract method actually is.
Given that derived classes should provide more (specific) behaviour compared to their parents it seems to go against OO principles to actually remove functionality by overriding a concrete method with an abstract one.



The new subclass that contains the overriding abstract method would be an abstract class. The abstract class could not be instantiated. Instead, the abstract class would just serve as an abstract superclass that requires any concrete subclass to provide a new implementation of the abstract method.

As I mentioned earlier, it is unlikely that you would find something like that in the first revision of a product. It is more likely that you would find something like that in a later revision where new functionality is has been added that was not envisioned by the original design team.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract methods