• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Local class program error  RSS feed

 
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


/* 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.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
author
Posts: 23821
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I would like to access z(String,String) constructor.how can I print s3 in that constructor.
Here is the updated program.

 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naseem,

Thanks for your time. This is what exactly i want. It is so nice to hear back from you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!