• 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

Doubt - Code

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class TestIntw
{
public static void main (String [] args)
{
System.out.println("Hello");
}
}

In the above code, without changing the main , how can we print "Hello world" instead of "Hello". And also "Hello" should not be printed. Only "Helloworld" should be printed.

[ March 01, 2007: Message edited by: Shiaber Shaam ]
[ March 01, 2007: Message edited by: Shiaber Shaam ]
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since java is open source now we can change the behavior of System.out.println(String s).
jeroen.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I highly doubt that this is a mock SCJP question, but okay....

How about adding a static initializer that displays "Hello World", and calls exit(), so that the main method doesn't run?

Henry
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a debugger? Use AspectJ to write an aspect with a pointcut to catch the call to System.out.println()? Dunno, you going to tell us?
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shaiber,

Here we go....

import java.io.*;
public class TestIntw
{
public static void main (String [] args)
{
System.out.println("Hello");
}
}

class System{

static final PrintStream out = new PrintStream(java.lang.System.out){
public void println(String s){
java.lang.System.out.println("Helloworld");

}
};
}

Lets Rock
 
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic