| Author |
Local class program error
|
Shiva Mohan
Ranch Hand
Joined: Jan 05, 2006
Posts: 465
|
|
/* symbol : constructor Z (java.lang.String,java.lang.String) location: class Z ppp () { new Z("s5","s6");} 1 error*/ but i have the z(final String s5,String s6) constructor in Z.I couldn't figure out the way to correct this.please help me.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Z is a method local class. You cannot access it from ppp() because Z is available only within the method body of priya(). What exactly are you trying to do?
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Shiva Mohan
Ranch Hand
Joined: Jan 05, 2006
Posts: 465
|
|
Thanks for the reply. I was doing one mock exam question which is non static member class. The above program, that ppp() constructor works fine.But I changed that program in method local class.this time,the constructor ppp() is not working.How come the non static member class is working and method local class is not working?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
The above program, that ppp() constructor works fine.But I changed that program in method local class.this time,the constructor ppp() is not working.How come the non static member class is working and method local class is not working?
The same reason why a constructor can't access a local variable of a method -- it is not in scope. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Shiva Mohan
Ranch Hand
Joined: Jan 05, 2006
Posts: 465
|
|
But I would like to access z(String,String) constructor.how can I print s3 in that constructor. Here is the updated program.
|
 |
Naseem Khan
Ranch Hand
Joined: Apr 25, 2005
Posts: 809
|
|
Hi Siva, Z is only visible inside priya() method. Yu can't access it outside. You have to create an instance of Z inside priya() method like this... Naseem
|
Asking Smart Questions FAQ - How To Put Your Code In Code Tags
|
 |
Shiva Mohan
Ranch Hand
Joined: Jan 05, 2006
Posts: 465
|
|
Hi Naseem, Thanks for your time. This is what exactly i want. It is so nice to hear back from you.
|
 |
 |
|
|
subject: Local class program error
|
|
|