Methods in Java Objective Questions and Answers for placement

Methods in java:
What is the output of the following program?
class MyClass
{
public static void main(String[] args)
{
int x;
x=test();
System.out.println("x="+x);
}
static int test()
{
System.out.println("Inside Test()");
}
}
A.
Inside Test()
x=0
B.
Compilation Error
C. None of the Above

What is the output of the following program?
class MyClass
{
public static void main(String[] args)
{
int x;
System.out.println("Begin Main");
x=test();
System.out.println("End Main");
}
static  test()
{
System.out.println("Inside Test()");
return 0;
}
}

Can we initialize a variable like this?
class MyClass
{
public static void main(String[] args)
{
int i=test();
System.out.println("i="+i);

}
static int  test()
{
return 10;

}
}

http://www.placementyogi.com/java-objective-questions/methods-in-java-level1/1

Comments

Popular posts from this blog

Cryptarithmetic Problems with solution for eLitmus pH Test CAT Cryptarithmetic

eLitmus Study Material eLitmus Syllabus for pH Test eLitmus

CyberLink YouCam Dark Image Solution