WorksheetsCode Junction 4
Total questions: 20
Worksheet time: 43mins
Number of primitive data types in Java are?
6
7
8
9
What is the size of float and double in java?
32 and 64
32 and 32
64 and 64
64 and 32
Find the output of the following code:
int Integer = 24;
char String = ‘I’;
System.out.print(Integer);
System.out.print(String);
compile error
throws exception
I
24 I
Find the output of the following program:
public class Solution{
public static void main(String[] args){
short x = 10;
x = x * 5;
System.out.print(x); } }
50
10
compile error
exception
Find the output of the following program:
public class Solution{
public static void main(String[] args){
byte x = 127;
x++;
x++;
System.out.print(x); } }
-127
127
129
2
Find the output of the following program.
public class Solution{
public static void main(String[] args){
int[] x = {120, 200, 016};
for(int i = 0; i < x.length; i++){
System.out.print(x[i] + “ “); } } }
120 200 016
120 200 14
120 200 16
none
Find the value of A[1] after execution of the following program.
int[] A = {0,2,4,1,3};
for(int i = 0; i < a.length; i++){
a[i] = a[(a[i] + 3) % a.length]; }
0
1
2
3
Identify what can directly access and change the value of the variable res.
Package com.mypackage;
Public class Solution{
Private int res = 100; }
any class
only solution class
any class that extends solution
none
Identify the output of the following program.
String str = “abcde”;
System.out.println(str.substring(1, 3));
abc
bc
bcd
cd
Identify the output of the following program.
Public class Test{
Public static void main(String argos[]){
String str1 = “one”;
String str2 = “two”;
System.out.println(str1.concat(str2)); } }
one
two
onetwo
twoone
How many objects will be created in the following?
String a = new String(“Interviewbit”);
String b = new String(“Interviewbit”);
Strinc c = “Interviewbit”;
String d = “Interviewbit”;
2
3
4
none
Find the output of the following code.
if(1 + 1 + 1 + 1 + 1 == 5){
System.out.print(“TRUE”); }
else{
System.out.print(“FALSE”); }
TRUE
FALSE
compile error
none
Find the output of the following code.
Public class Solution{
Public static void main(String… argos){
Int x = 5;
x * = (3 + 7);
System.out.println(x);
50
22
10
none
Identify the return type of a method that does not return any value.
int
void
double
none
Identify the modifier which cannot be used for constructor.
public
protected
private
static
What is the variables declared in a class for the use of all methods of the class called?
object
instance variable
reference variable
none
Find the output of the following code.
Public class Solution{
Public static void main(String args[]){
Int i;
for(i = 1; i < 6; i++){
if(i > 3) continue; }
System.out.println(i); } }
3
4
5
6
How many times will “Interviewbit” be printed.
Int count = 0;
do{ System.out.println(“Interviewbit”);
count++; }
while(count < 10);
8
9
10
11
Identify the infinite loop.
for(; ;)
for(int i=0; i < 1; i--)
for(int i = 0; ;i++)
All of the above
Exception created by try block is caught in which block?
catch
throw
final
none
