This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Why doesn't this class compiles? 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 » Java » Java in General
Bookmark "Why doesn Watch "Why doesn New topic
Author

Why doesn't this class compiles?

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167


The class Person is inside Lab1 class.In Lab1 a static variable pers of type Person is declared and used inside the main().Even though pers is of static type why is not possible to compile Lab1.If Person class is made static Lab1 compiles and returns the expected output.Since pers is inside main() it is of type static and it will refer to what ever exact object it will be pointed to.

Varuna
[ December 11, 2008: Message edited by: Varuna Seneviratna ]

Varuna Seneviratna
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 818



I changed the way the of the object creation of the method-local inner class and it works fine.
I hope this explains what you are looking for.

Thank you.


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
Originally posted by Sudipto Shekhar:


I changed the way the of the object creation of the method-local inner class and it works fine.
I hope this explains what you are looking for.

Thank you.


So when referring to a class it's full path must be specified? Is it?

Regards Varuna
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 818

Yes.
The class you created inside the main() is a method local inner class.
There is a special case with the method local inner classes.I recommend you to go through the static inner class, method local inner class and the anonymous inner and argument-defined anonymous inner class in deep.
They are very important concepts of Java and are very helpful in certain cases.

Hope this helps.
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
Originally posted by Sudipto Shekhar:


I changed the way the of the object creation of the method-local inner class and it works fine.
I hope this explains what you are looking for.

Thank you.

[ December 11, 2008: Message edited by: Varuna Seneviratna ]
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 818

I am sorry I did not get you!
Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
Originally posted by Sudipto Shekhar:
I am sorry I did not get you!


You were correct I did not change the tester() method when compiling the program in my machine that's why the theory you said did not work in my machine


Varuna
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
Did you actually intend to have the Person class inside the Lab1 class? That appears very strange to me.
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 818

Yes, Inner classes are the helper class to the outer class in most of the cases.

The best example is of event handling.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
I presume this is an exercise; if you do want inner classes, this question is too difficult for beginner's. Moving.

******************************************************************************

Do a Google search for Bruce Eckel's Thinking in Java; the 3rd edition used to be available as an HTML and it has a nice chapter about inner and nested classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why doesn't this class compiles?
 
Similar Threads
State Exception
Anonymous Inner classes
Interface Implementation
Thanks anyway
private constructor