File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract method INFO Plz? 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 "abstract method INFO Plz?" Watch "abstract method INFO Plz?" New topic
Author

abstract method INFO Plz?

Kiran Chand Panga
Ranch Hand

Joined: Feb 02, 2006
Posts: 31
abstract class A
{
abstract short m1();
short m2() { return (short) 420; }
}

abstract class B extends A
{
// missing the code ??
short m1() { return (short) 42; }
}

which of the following statements are true?
A. Thc code will compile with no changes.

B. Class B must either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.

C.It is legal, but not required, for Class B to either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.


I didn�t understand the B and C options. A and C are the correct Answer. Why C is the correct answer?
Can any one tell about abstract class and method? If any abstract method extends another abstract class then what we have does in the base abstract method? Where I can get good java study material?
[ February 09, 2006: Message edited by: Kiran Chand Panga ]

Thanks & Regards <br /> <br />Kiran Chand Panga<br />SCJP1.4
Ankit Pradhan
Greenhorn

Joined: Jan 05, 2005
Posts: 16
Since class B is an abstrat class itself so it is not even necessary for it to implement any of the abstract methods of the super class.
Moreover since m2 is not an abstract method in class A, so any class which extends class A(whether it may be itself abstract or not) doesnt need to implement or declare this method.So option B is not right.

Answer C is perfectly all right because there will be no harm if you override the m2 method of class A in class B. Even if you declare the method m2() as abstract in class B then also it will work.(Remember class B is an abstract class & only abstract classes can have abtract methods).

Basically an abstract class is a sort of Contract between the implementing class and itself. It says that the implementing class will always implement the abstract methods of the abstract class.
If you take the example of "interfaces", it will be clear that interfaces are 100% abstract classes in other sense. All of the method declaration given inside the Interface will internally be treaten by the compiler like
"public abstract".

Hope that clarifies.
You can refer any Standard Java reference guide for these concepts.

Regards,
Ankit Pradhan
abstract class A
{
abstract short m1();
short m2() { return (short) 420; }
}

abstract class B extends A
{
// missing the code ??
short m1() { return (short) 42; }
}

which of the following statements are true?
A. Thc code will compile with no changes.

B. Class B must either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.

C.It is legal, but not required, for Class B to either make an abstract declaration of method m2() or implement method m2() to alllow the code to compile.


I didn�t understand the B and C options. A and C are the correct Answer. Why C is the correct answer?
Can any one tell about abstract class and method? If any abstract method extends another abstract class then what we have does in the base abstract method? Where I can get good java study material?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract method INFO Plz?