Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Green Exam #1: Question 11

 
Brett Swift
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mine must be declared abstract because it inherits an abstract method from its parent, MineBase.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Brett Swift
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic