File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How do you solve this...??!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How do you solve this...??!!" Watch "How do you solve this...??!!" New topic
Author

How do you solve this...??!!

Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Here is the code...
public class Bill {
private static int i ;
private int j;
public static void staticMethod() {
System.out.println("static method in bill" );
}
interface INested { int Y2K = 2000; }
protected static class Nested implements INested {
private int k = Y2K;
private static int x ;
private void nonstatic() {
int ii = i;
staticMethod();
}
public static void main (String args[]) {
int ii = i;
Bll b = new Bll();
b.staticMethod();
}
}
}
*****when i run it*****
C:\SCJP>java Bill$Nested
static method in a bill
***********************
Perfect. Now is there a way to access the nonstaticmethod()?
in Nested class from its entry point main???
Any help please...?
Vanitha Sugumaran
Ranch Hand

Joined: Apr 11, 2001
Posts: 356
Hi Ragu,
You can't access nonstatic() using the object reference b since this method is not visible to class Bill. But you can create an instance of the static class and access the method through it.

Correct me if I am wrong,
Vanitha.
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by Vanitha Sugumaran:
[B]Hi Ragu,
You can't access nonstatic() using the object reference b since this method is not visible to class Bill. But you can create an instance of the static class and access the method through it.

Correct me if I am wrong,
Vanitha.[/B]


thankx for your response
Yeah it will work, but the irony is
instance of a static class? hmmm
sounds little weird to me...
But i guess that seems to be the only way to access it
Probably the compiler just ignores for a moment the top-level nested class and handles it to be just an non-static inner class? (I dont know, but it looks like it though)
Just another X-files mysteries...
Thankx guys
and especially to Vanitha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you solve this...??!!