• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

please look at it!!

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following code is about a inner class, the right output is "Sample", it make me confused, i think it should be nothing,
please help me!!
-----------------------------------------------------------
public final class Test4
{
class Inner
{
void test()
{
if (Test4.this.flag);
{
sample();
}
}
}
private boolean flag = false;
public void sample()
{
System.out.println("Sample");
}
public Test4()
{
(new Inner()).test();
}
public static void main(String args [])
{
new Test4();
}
}
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is because you have a semicolon at the end of your if statement .

Originally posted by David chenjl:
the following code is about a inner class, the right output is "Sample", it make me confused, i think it should be nothing,
please help me!!


 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what happens:
The constructor is called from main
The constructor calls superclass contructor
Initializers are executed (flag is set to true)
The rest of the constructor is executed
So, call to sample() occurs after flag is set to true.
 
reply
    Bookmark Topic Watch Topic
  • New Topic