File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Local Classes?

 
Amandeep Waraich
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is Marcus Test #1 Qn no. 30
public class MyClass1 {
public static void main(String argv[]){ }
/*Modifier at XX */ class MyInner {}
}
What modifiers would be legal at XX in the above code?
1) public
2) private
3) static
4) friend

My answer is 1,2..but the answer given is 1,2,3. Khalid's book clearly states on page 238:
"A local class cannot be specified with the keyword static."
Yeah, I know that it also states that if the context is static, then the local class is implicitly static, but does this mean that you CAN use the keyword static if the class is implicitly static?
Tbanks,
Aman

 
rajsim
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does compiler reject "static" for the above example?
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
hi Amandeep Waraich
The answer are indeed 1,2 & 3 as this is a top level nested class not a local inner class. note the close of braces of main method given below in bold
public class MyClass1 {
public static void main(String argv[]){ }
/*Modifier at XX */ class MyInner {}
}

However this is not possible and will give a compile error
public class MyClass1 {
public static void main(String argv[]){
static class MyInner {}
}
}
The above class MyInner is inside a method main
Regds
Rahul

[This message has been edited by rahul_mkar (edited July 24, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
The Correct answeres are 1,2 and 3. Assume inner class as a
member of the top-level class. So private, public and static are
legal modifiers for members.
Regards
Hemant.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic