Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green Exam #1: Question 11 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green Exam #1: Question 11" Watch "Marcus Green Exam #1: Question 11" New topic
Author

Marcus Green Exam #1: Question 11

Brett Swift
Ranch Hand

Joined: May 22, 2002
Posts: 61
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
Mine must be declared abstract because it inherits an abstract method from its parent, MineBase.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
"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


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Brett Swift
Ranch Hand

Joined: May 22, 2002
Posts: 61
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Green Exam #1: Question 11