*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding a concrete method by abstract method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding a concrete method by abstract method" Watch "overriding a concrete method by abstract method" New topic
Author

overriding a concrete method by abstract method

shakunthala Divakar
Greenhorn

Joined: Aug 01, 2007
Posts: 13
Hi Javaranchers
The below quetion is from a Mock exam
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

Answer Given is e.None of the above.
but i expected b.
And i tried with some code to test


the above shows error at line 1 saying,This metthod requires body instead of ;
Then the anwer given in mock exam is wrong.....am i right???

thanks
Shakunthala Divakar
Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
What about option a?
>> a. An abstract method can not be overridden by an abstract method.

I thought that was true. Can someone please explain why not?
shakunthala Divakar
Greenhorn

Joined: Aug 01, 2007
Posts: 13
Hi javaranchers
I am sorry.The code i was trying was wrong.
i have missed abtract modifier for print method.
The statement
An instance method that is not abstract can not be overridden by an abstract method...is right
shakunthala Divakar
Greenhorn

Joined: Aug 01, 2007
Posts: 13
sorry again
The statement is An instance method that is not abstract can not be overridden by an abstract method...is NOT right.
Hi Neha Bhattad ,
i think even option a. is not true so the given anwer in mock exam is right.
Try the below code


Thanks
shakunthala Divakar
Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
Shakunthala,

In your code:


The abstract method in Subclass is the same as the one in the superclass...is it really overridden?? To me it looks like the method is plain inherited.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy,

yes, it compiles. It even compiles with an annotation:


But is this really an override?


Bu.


all events occur in real time
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Hi Bu

To me method "print" doesn't seem to be overridden as neither of them have an implementation. Hence there is no behavior in the base class "print" which can be overridden in the sub class. My doubt is, if this is not overriding then what it actually is ? Is it something like base and sub classes having same named private methods which is again not a case of overriding.
Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
From Sun Java

>> An abstract class can override an abstract method by providing another abstract method declaration.

Consider the case of an abstract method in an interface being overriden by an implementing abstract class.



>>An instance method that is not abstract can be overridden by an abstract method.

Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
Forgot to mention the second code:
>> results in a compile-time error because the invocation super.toString() refers to method toString in class Point, which is abstract and therefore cannot be invoked.
Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
Hi Bu,

So is that truly an override? Does using the @Override change anything?

Thanks
Neha.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: overriding a concrete method by abstract method