• 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

Anonmyous class

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How do i access th method of the anonmyous class
This is the code..
interface mycode
{
void display();
}
public class enclosing
{
public void mymehtod()
{
new mycode()
{
public void display()
{
System.out.println("display of anonmyous class");
}
}
}
public static void main(String a[])
{
enclosing e = new enclosing();
??? // how do i access display()
}
}
-Sanjana
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
First of all, this program won't compile. Your definition of anonymous inner class itself is not proper (no ';' after '}'). Secondly, if you don't have a reference to your anonymous innerclass, you won't be able to use it.
 
sanjana narayanan
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hari,
I am aware that the code will not compile. I just wrote a code which wud help me to convey what i was trying to ask.
Can u pl explain it with a code sample..
-Sanjana
-
 
H Gokulam
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
See this code. I think this will clarify your doubts.

If anything is not clear please specify.
 
sanjana narayanan
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hari,
I understood your code. Thank u..
-Sanjana
 
reply
    Bookmark Topic Watch Topic
  • New Topic