This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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: 23811
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.
 
Oh the stink of it! Smell my tiny ad!
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!