aspose file tools
The moose likes Beginning Java and the fly likes asking about interface 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Storm Applied this week in the Other Open Source APIs forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "asking about interface 1" Watch "asking about interface 1" New topic

asking about interface 1

kumar abhay
Ranch Hand

Joined: Oct 02, 2001
Posts: 53

Question iii:-Main method of class Myclass is a static block n a static object is being made in
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 thanks in advance
take care
with regards
(edited by Cindy to format code)
[ March 18, 2002: Message edited by: Cindy Glass ]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
a static object is being made in
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
I agree. Here's the link:
subject: asking about interface 1