aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. abstract class and method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. abstract class and method" Watch "Reg. abstract class and method" New topic
Author

Reg. abstract class and method

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
Following is from JavaCaps mock exam #2

The correct answer given is C.
But i think it should be A, C because we get compiler
error for both the class declaration adn the method Test().
Mariusz Szurnacki
Ranch Hand

Joined: Sep 12, 2001
Posts: 44
> But i think it should be A, C
Hi!!!
I agree. if we have an abstract method in the class,
then also the class must be abstract.
So we have to remove abstract modifier from method or add abstract modifier to the class. In this way, correct answers are
A i C.
Have a nice day,
Mariusz

<BR>
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Yeah Ranchers,
The answer is A and C. A class with abstract method MUST be
declared as "abstract". An abstract method/ native method CAN NOT
have a body /definition.
I guess this clears this issue.
Ravindra Mohan.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
So I think the right answer is still only C, since the method Test has a body ! If you just remove the abstract modifier from the method declaration of Test it compiler fine. BUT if you add the abstract modifier to the class declaration it won't compile !!
Anyone ?
Val


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
If without considering the assumptions, i compile
the code, it will give both the class error as well as
the method error. So i still think it is A,C

To make the code compile we can do "either" of the below:
1.Remove the method body for Test() and declare the class as abstract.
2. Remove the abstract keyword from Test() method.
Correct me if wrong ..
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Angela,
First, the only error I get by compiling the code is about the body of the abstract Test method, but nothing about the class declaration.
I agree with you BUT, in the proposed answers there is no "In the body of the Test method" !!! The only thing about the Test method is about its declaration so considering the given answers, the only correct answer is C, because if you remove the abstract modifier in the declaration of the method Test, it will correct the error given by the compiler !!!
Val
Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
I get the below two errors :
MyTest.java:1: MyTest should be declared abstract; it does not define Test() in MyTest
public class MyTest {
^
MyTest.java:8: abstract methods cannot have a body
public abstract void Test() {
^
2 errors

So acc. to me the answers should be A,C
james hoskins
Ranch Hand

Joined: Jun 28, 2001
Posts: 31
i think this discussion is more about poor question writing than code. both answers could be seen as correct depending on your viewpoint. everyone picked up on the need for an abstract class declaration and removal of method body, ambiguous questions can drive you mad.
kind regards,
james.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Angela,
James is right, I'm sorry !

Val
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg. abstract class and method