• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why doesn't this class compiles?

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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 ]
 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Varuna Seneviratna
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry I did not get you!
 
Varuna Seneviratna
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you actually intend to have the Person class inside the Lab1 class? That appears very strange to me.
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic