Core Java - Handson & Assignments - 1
Core Java - Handson & Assignments - 1
1)What is the result of trying to compile and run the following code.
void aMethod()
{
float f = (1 / 4) * 10;
int i = Math.round(f);
System.out.println(i);
}
1. 2
2. 0
3. 3
4. 2.5
5. 25
1. int i = 0XCAFE;
2. boolean b = 0;
3. char c = 'A';
4. byte b = 128;
5. char c = "A";
1. Compiler error.
2. Compiles and runs printing out 2
3. Compiles and runs printing out 1
4. An ArrayIndexOutOfBounds Exception at runtime
1. Compiler error.
2. Will throw a NoSuchMethod error at runtime.
3. It will compile and run printing out "10"
4. It will run with no output.
5. It will run and print "10" and then crash with an error.
long longArr[];
int intArr[] = { 7 ,8 , 9};
longArr = intArr;
1. Yes
2. No
1. float f = \u0038;
2. long L2 = 2L;
3. float f = 1.2;
4. char c = '/u004E';
5. byte b = 100;
8)What is the result of trying to compile and run the following code.
{
double d = - 22.22222;
System.out.println(Math.ceil(d));
}
}
1. 22
2. 22.0
3. -22
4. -23
5. -22.0
6. 23.0
System.out.println(f);
}
}
1. Compiler error
2. Runtime error
3. Runs and prints "false"
4. Runs and prints "true"
1. Compiler error
2. Runtime error
3. Runs and prints "false"
4. Runs and prints "true"
}
}
1. Compiler error
2. Runtime error
3. Runs and prints "256"
4. Runs and prints "0"
5. Runs and prints "127"
1. Yes
2. No
3) Is this legal ?
1.Yes
2.No
1. int i = 16.0;
2. byte b = 16.0;
3. float f = 16.0;
4. double d = 16.0;
5. char \u0063 = '\u0063';
1. Compiler error
2. Runtime exception
3. Compiles and runs printing out 0