Help coderanch get a
new server
by contributing to the fundraiser
  • 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

method calling

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract class GreaterOne
{
abstract void doSomething () ;
}
class Test {
GreaterOne doSomething ( )
{
class Inner extends GreaterOne
{
void doSomething ( )
{
System . out .println ( " I Am Weasel " ) ;
}
};
return new Inner ( ) ;
}
};
class ZZY {
public static void main ( String ka [ ] )
{
Test t = new Test ( ) ;
GreaterOne g = t . doSomething ( ) ;
g . doSomething ( ) ;
}
}

Here i am not understanding how code goes and also why is the out put result only one instead of two output as we have two reference calling the method dosomething.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are 2 different doSomething methods:
  • Test.doSomething() creates and returns a new instance of Inner, upcast to type GreaterOne.
  • Inner.doSomething() executes a println.
  •  
    Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
    We need your help - Coderanch server fundraiser
    https://coderanch.com/t/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic