wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Exam 1 question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam 1 question" Watch "Marcus Exam 1 question" New topic
Author

Marcus Exam 1 question

Raj Mehra
Ranch Hand

Joined: Nov 20, 2000
Posts: 51
Q 30) from Marcus Green Exam 1
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
The correct answers given are 1,2 and 3. Can someone explain this.


SCJP2 2001 84%<br />SCJD2 2003 100%
vadiraj vd
Ranch Hand

Joined: Dec 15, 2000
Posts: 68
Your code :



<pre>

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

</pre>

Hi Raj,
The class <code> class MyInner {} </code>defined inside the class
<code> public class MyClass1{} </code> is essentially a nested class. The nested class can be Top level nested class or inner class.
The difference is toplevel nested classes are static and inner classes are not.
All access specifiers can be applied to these classes.(public, private,protected or no modifier). and one access specifier(i.e. static) can be applied.


So the answers.
Hope this helps.
Regards
-----
vadiraj

------------------
********************
There's a lot of I in J.
********************


Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************
Vijay, Bakshi
Ranch Hand

Joined: Nov 14, 2000
Posts: 40
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
The correct answers given are 1,2 and 3. Can someone explain
Note that the class is outside the method main (ie it is not local), therefore it can be a static-inner(static can be used) class or a non-static innner class and both of these can have any visibility modifiers(public, protected, private & none (default)) (refer the table in Khalid Mughal's book on classes/inner classes). Obviously the 4th option is not valid. Hope this will help you.
Raj Mehra
Ranch Hand

Joined: Nov 20, 2000
Posts: 51
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Exam 1 question
 
Similar Threads
local nested class
Static Local Classes?
modifier for inner class
Modifiers for Local Inner classes
can inner class be "public"? if outer class is "public" already.