Question iii:-Main method of class Myclass is a static block n a static object is being made in it.how? Question iv:- -Main method of class Myclass is a static block tell me how non-static methods are called from it? i hope that you would do that.so thanks in advance take care with regards kumar (edited by Cindy to format code) [ March 18, 2002: Message edited by: Cindy Glass ]
a static object is being made in it.how? There is no such thing as a static object (there ARE static variables). The only object made in main is referenced by m. It is a particular instance - there is nothing static about it. Static means "not relating to a particular instance" or in other words "relating to the whole classfile". The class o is an inner class to A. Because it is in an interface it is static and public. per the JLS:
[qb]9.5 Member Type Declarations/qb] Interfaces may contain member type declarations (�8.5). A member type declaration in an interface is implicitly static and public.
When the main method is invoked using >java Myclass the class is loaded and all static stuff (variables, methods, member classes etc) is available to be used without creating any instances of Myclass. Of course then the next thing that you do is CREATE an instance of Myclass to muddy the waters. You can create the instance of O without an instance of Myclass and without the typical static syntax of saying Myclass.O o = new Myclass.O(); because both main and O are IN Myclass - try it.
Main method of class Myclass is a static block tell me how non-static methods are called from it?
The only method that you called is m.method(). In that case you used an instance to call the method. That is what non-static methods are all about. They need an instance to call them on.
"JavaRanch, where the deer and the Certified play" - David O'Meara