6)
What will be the output of following program?
public class prg {
public static void main(String[] args) {
char a=0x41; //Unicode of 'A'
char b=0x42; //Unicode of 'B'
System.out.print(a+"" + b+"");
System.out.print("-");
System.out.print(a+b);
}
}
- AB-AB
- AB-131
- AB-ERROR
- A B -131
Correct Answer: 2
AB-131
a+"" and b+"" will be converted into string, .toString() or +"" after variable or value converts value into the string and a+b will be added because they are not converted into string. Hence output will be AB-131.
7)
What should be the name of java program file containing this program?
public class MyPrg
{
public static void main(String args[])
{
System.out.print("IncludeHelp");
}
}
- MyPrg.class
- MyPrg.java
- MyPrg
- Any file name with java extension
Correct Answer: 2
MyPrg.java
In this program class MyPrg is public, so we can not take any file name, we must save this program by MyPrg.java file name otherwise Compilation error is occurred.
10)
What will be the output of following program?
class Prg
{
public static void main(String args[])
{
const int a=10;
System.out.println(a);
}
}
- 10
- a
- Unprintable Character
- Error
Correct Answer: 4
Error:
illegal start of expression.
JAVA does not support the const keyword, instead of const, final keyword is used.