Question 11. What will be the result of attempting to compile and run the following code? abstract class MineBase { abstract void amethod(); static int i; } public class Mine extends MineBase { public static void main(String argv[]){ int[] ar=new int[5]; for(i=0;i < ar.length;i++) System.out.println(ar[i]); } }
1) a sequence of 5 0's will be printed 2) Error: ar is used before it is initialized 3) Error Mine must be declared abstract 4) IndexOutOfBoundes Error
The answer to this is 3). This is Marcus Green's reasoning: "A class that contains an abstract method must itself be declared as abstract. It may however contain non abstract methods. Any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself. " However, I don't see the abstract method in the 'Mine' class... Is this referring to the variable 'i'? That definately doesn't seem to make sense to me, so it must be something else? Anyone have any solid ideas on this? Thanks! Brett
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Mine must be declared abstract because it inherits an abstract method from its parent, MineBase.
"Any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself. " Which of the methods in MineBase does Mine define? Marcus
Thank you. I think I am at the point where I need to take my break for the day. That question seems much simpler now than when I was first looking at it!