Font size
WorksheetsDatatypes and Flowcontrol
Total questions: 15
Worksheet time: 8mins
Which of the following is NOT a primitive datatype?
byte
boolean
String
int
What are the correct ways to declare a array? (Select appropriate answer)
int a[][] = new int[5][5];
int a[][] = new int[][4];
int a[4][]=new int[][4];
int a[4][4];
Predict the output of the following code.
public class ColorTest
{
public static void main(String args[])
{
char choice='r';
switch(r)
{
case 'Y': case'y':
System.out.println("Yellow");
case 'R': case 'r' :
System.out.println("Red");
default:
System.out.println("Invalid color");
}
}
}
Red
Invalid Color
Compilation fails
Red
Invalid color
Which of the following statements are CORRECT about Arrays in Java?
Stores Homogeneous Data
Size cannot be changed during run time
Array index starts at 1
Stores only user defined objects
What is the output of the following code?
public class Test
{
public static void main(String args[])
{
int a[] = new int[2];
int index =1;
System.out.println(a[index++]);
}
}
ArrayIndexOutofBoundsException
null
0
Runtime Error
Predict the output.
1 public class LiteralTest {
2 public static void main(String args[]) {
3 float f1=4.0;
4 float f2 = 2.0f;
5 float result= f1 * 2;
6 System.out.prinltn(result);
7 } }
Compilation Error at line no.3
Compilation Error at line no.4
Prints 8.0
Compilation Error at line no.6
Public class TestOperator {
public static void main(String args[]) {
System.out.println(6^2);
} }
2
24
Compiler Error
No output
What will be the output if we compile and execute the following code?
public TestBoolean{
public static void main(String args[]){
boolean b[] = new boolean[2];
boolean f = true;
System.out.println(b[0]+"::"+f);
if(b[1])
System.out.println(" in IF block");
else
System.out.println("in ELSE block");
} }
false::true
in ELSE block
true::true
in IF block
false::true
in IF bloack
true::true
in ELSE block
To copy array elements from one array to another array, we can use (a)
The advantages of java array are _________________ and ____________________________
(a)
Java supports automatic garbage collection.
True
False
Replace the following code with suitable equivalent.
if(a>b)
max= a;
else
max=b;
(a>b)? max=a: max=b;
max = (a>b)? a: b;
max = a^((a^b) & (-(a<b)));
max= b^((b^a) & (b<a))
which access specifier strongly supports data hiding?
default
private
public
protected
(a) operator is used to compare an object with a specific type.
Which of the following classes will be the parent class of all user-defined classes in java?
Class
Object
String
No parent class for user defined classes
