• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Doubt - Code

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • 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
  • 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: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic