• 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

anonymous class

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class C1
{
public void m1()
{
System.out.println("m1 method in C1 class");
}
}
class Ctest
{
public C1 m1()
{
return new C1()
{
public void m1()
{
System.out.println("m1 method in anonymous class");
}
};
}
public static void main(String args[])
{
C1 obj1=new Ctest().m1();
obj1.m1();//line 2
}
}

problem is from where line2 comes into play
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've observed from your many posts that you don't use code tags Please UseCodeTags
,I would have done it for you, but I cant.and UseAMeaningfulSubjectLine

problem is from where line2 comes into play



and please explain exactly what do wish to know.


Hope this helps
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
line 2 will invoke method on the anonymous class only.

Because the anonymous class extends the Class C1 and overrides the method m1() from the class C1. So at runtime the method from the subclass will be invoked in the main() method when it invokes

(as per the Overriding principles).

Hope this clears your doubt.
[ April 17, 2008: Message edited by: Thirugnanam Saravanan ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic