• 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

Output missing something...

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all...
Can someone explain me why in the below program, the Output
does not print the Char 'V'.
class Process
{
boolean b;
public Process(int x)
{
System.out.println((char)x);
}
}
public class Test
{
Process p3 = new Process('V');

public static void main(String[ ] args)
{
Process p4 = new Process('X');
}
static Process p1 = new Process('J');
static Process p2 = new Process('$');
}
The Output of the Above Prog:-
J
$
X
Why doesn't the Char 'V' is not included in Output ?
Thanks.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shah Chunky:
Hello all...
Can someone explain me why in the below program, the Output
does not print the Char 'V'.
public class Test
{
Process p3 = new Process('V');

public static void main(String[ ] args)
{
Process p4 = new Process('X');
}
static Process p1 = new Process('J');
static Process p2 = new Process('$');
}
The Output of the Above Prog:-
J
$
X


In your Test class the variable p3 is an instance variable so it is never created until you create an actual Test object. The variables p1 and p2 are static so they are created and instantiated when the Test class is loaded. Then in main you specifically create a Process object so it too prints. To see the 'V' printed, just create an instance of your Test class in main.
add a line like this:
Test newTest = new Test();
and then V will print.
hth
Dave
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic