java Assignment2
java Assignment2
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
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);
}
}
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
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
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
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
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
1021
1122
1121
1020
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);
}
}
}
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
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
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)
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
23) What should be the operands for compound assignment operators( ex:- Syntax :
op1 += op2)
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
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
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