1) What is the output for the following program
class Test1
{
public static void main(String[] args)
{
int a = 97;
switch(a)
{
case 97:
System.out.println("int");
break;
case 'a':
System.out.println("char");
break;
default:
System.out.println("Nothing");
}
}
}
char
int
compile time error
Nothing
2)What is the output for the following program
class Test2
{
public static void main(String[] args)
{
String str = false+"";
switch(str)
{
case ""+false:
System.out.println("true");
break;
case true+"":
System.out.println("false");
break;
default:
System.out.println("true and false");
}
}
}
true and false
false
true
compile time error
3)What is the output for the following program
class Test3
{
public static void main(String[] args)
{
int num = 97;
switch(num)
{
case demo('a'):
System.out.println('a');
break;
case demo('b'):
System.out.println('b');
break;
default:
System.out.println("dafault");
}
}
public static int demo(char ch)
{
return ch;
}
}
default
b
a
compile time error
4)
import java.util.Scanner;
public class Test4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter String1 : ");
String str1 = sc.next();
System.out.println("Enter String2 : ");sc.next();
String str2 = sc.nextLine();
System.out.println(str1+str2);
}
}
What is the output of this program if user enters like this,
Enter String1 :
123
Enter String2 :
456
Compile Time Error
123456
123
456
5) What is the output for the following program
public class Test5 {
public static void main(String[] args) {
if(test1(test2('a')))
{
System.out.println("Kadavuley");
}
else
System.out.println("Ajithey");
}
public static boolean test1(String str)
{
return true;
}
public static String test2(int a)
{
return a+"Hello";
}
}
Ajithey
Kadavuley
Compile Time Error
No output
6) What is the output for the following program
public class Test6 {
public static void main(String[] args) {
overLoad((char)97+1);
}
public static void overLoad(int a)
{
System.out.println(a);
}
public static void overLoad(char ch)
{
System.out.println(ch);
}
}
b
Compile Time Error
98
97
7) What is the output for the following program
public class Test7 {
public static void main(String[] args) {
if(true)
{
int a =10;
System.out.print(a);
}
int a = 20;
System.out.print(a);
}
}
10
20
Compile Time Error
1020
8) Which are all the following we cannot use in the method body as a statement
Condition
Switch statement
Expression
Import statement
9) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
if(true)
System.out.println("if block");
else if(true)
System.out.println("else if block");
else
System.out.println("else block");
}
}
else if block
else block
if block
Compile Time Error
10) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
boolean b = (boolean)true;
if(b)
System.out.println("if block");
else
System.out.println("else block");
}
}
else block
Compile Time Error
if block
Run Time Error
11) What is if statement
Decision Making Statement
Control Transfer Statement
Looping Statement
Branching Statement
12) Decision Making Statement are used to
Execute the instructions
Skip the instruction
Execute or Skip the instructions
Execute the instruction based on condition
13) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
int a = 10, b = 20;
int res = a>b++ && ++a<b ? b++ : b--;
System.out.print(a);
System.out.print(b);
}
}
1021
1122
1121
1020
14) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
switch((int)10L)
{
case (int)10.15:
System.out.print(20);
case (char)11.15:
System.out.print(40);
return;
default:
System.out.print(60);
}
}
}
Compile Time Error
20
204060
2040
15) Where we can use return statement
In the method body
In the case blocks of switch statement
In the class block (only inside class block)
outside the class block
16) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
System.out.println(Math.max(demo1(), demo2()));
}
public static int demo1()
{
return 10;
}
public static char demo2()
{
return 'a';
}
}
a
Compile Time Error
10
97
17) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
System.out.print(demo(true));
}
public static int demo(boolean b)
{
if(b)
return 10;
else
return 20;
System.out.print("TheEnd");
}
}
10TheEnd
Compile Time Error
TheEnd
20TheEnd
18) What is the output for the following program
public class Test1 {
public static void main(String[] args) {
System.out.println((char)(int)'a');
}
}
97
a
Compile Time Error
None of the Above
19) Which are the following is compile time error (with respect to method
declaration)
public static void test(int a,b,c)
public static int demo(int b=20)
static public String class(int a)
void check(int a)
20) What is the res value from the following snippet code
int a = 45;
int b = 20;
int res = a+=a=b;
20
90
65
40
21) Which one is not the characteristic of a method
We can call a method multiple times
Method is a member of the class
To execute a method we need to invoke
For method we can create an instance
22) What the modifiers will do
Behavioural changes for java members
control the accessibility
It will help a method to return a value
It is used to call a method
23) What should be the operands for compound assignment operators( ex:- Syntax :
op1 += op2)
op1-variable and op2-variable
op1-value and op2-variable
op1-variable and op2-expression
op1-variable and op2-value
24) While compiling the following expression what a compiler will do
expression - 10+10.15+'a'
Type Promotion
It will do narrowing
It will throw compile time error
It will execute the expression
25) What will happen when we perform addition operation between char data and
String data
String data will be concatenated with ascii value of char data
String data will be concatenated with char data
Compile Time Error
None of the above
26) What is the value that the following printing statement will print
System.out.println((10>20?false:true) ? true:false);
false
true
Compile Time Error
None of the above
27) Which are all the following are correct regarding to NOT operator
It will work with only Boolean data
It is used to negate the Boolean data
We can use NOT operator with condition
It will return Boolean
28) How switch statement will work
It will use == operator to compare switch and case block values
break statement is optional
We can use Boolean data in switch
For case block we can pass variable
29) What is the value that the following printing statement will print
System.out.println(10%10.5);
0
10.0
0.0
10
30) In which datatype we can store all the number type of data
String
int
float
double