Question
how to print a message to console without using main()
function?(do not use even static blocks also.)
Question Submitted By :: Rajavardhan Reddy K
I also faced this Question!!
Rank
Answer Posted By
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 1
using a static block you can print the message (string)s.o.p
Narender
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 2
use a constructor and declare a global object.
class message
{
public:
message("Hello world\n");
}a;
void main(){}
Vijay Nag
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 3
class testing{
public testing(){
System.out.println("Hello ");
}
}
public class TestClass{
static testing t = new testing();
public TestClass(){
}
}
Cvs
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 4
class testprint
{
static String print=testprint.toString("test");
public static String toString(String s)
{
System.out.println("I am Here");
return s;
}
}
Amit Dubey
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 5
public class classWithoutMain {
private static int x = load();
private static int load() {
System.err.println("This message will be printed");
System.exit(0);
}
}
Jaya
Re: how to print a message to console without using main()
function?(do not use even static blocks also.)
Answer
# 6
Sorry. Missing return statement in the former post
public class classWithoutMain {
private static int x = load();
private static int load() {
System.err.println("This message will be printed");
System.exit(0);
return 0;
}
}
Jaya