JAVA Basic
JAVA Basic
Answer: Option B
A. 6 B. 7 C. 8 D. 9
Answer: Option C
Answer: Option A
Answer: Option B
5. The smallest integer type is ......... and its size is ......... bits.
Answer: Option B
Answer: Option A
7. Determine output:
class A{
public static void main(String args[]){
int x;
x = 10;
if(x == 10){
int y = 20;
System.out.print("x and y: "+ x + " " + y);
y = x*2;
}
y = 100;
System.out.print("x and y: " + x + " " + y);
}
}
A. 10 20 10 100 B. 10 20 10 20
C. 10 20 10 10 D. Error
Answer: Option D
A. Two type are compatible and size of destination type is shorter than source type.
B. Two type are compatible and size of destination type is equal of source type.
C. Two type are compatible and size of destination type is larger than source type.
Answer: Option C
Answer: Option C
class A{
public static void main(String args[]){
byte b;
int i = 258;
double d = 325.59;
b = (byte) i;
System.out.print(b);
i = (int) d;
System.out.print(i);
b = (byte) d;
System.out.print(b);
}
}
C. 2 325 69 D. Error
Answer: Option C
A. float B. double
Answer: Option B
A. Prints 2.5
Answer: Option A
int Integer = 34 ;
char String = 'S' ;
System.out.print( Integer ) ;
System.out.print( String ) ;
A. Does not compile as Integer and String are API class names.
B. Throws exception. C. 34 D. S E. 34 S
Answer: Option E
A. 20 B. 21 C. 22 D. Compilation Error
E. Throws Exception
Answer: Option C
Answer: Option C
A. 34 34 B. 65 34 C. 65 65 D. 34 65
Answer: Option B
Answer: Option B
Answer: Option B
A. 2 B. 0 C. 3
D. 2.5 E. 25
Answer: Option B
class A{
int k;
boolean istrue;
static int p;
public void printValue(){
System.out.print(k);
System.out.print(istrue);
System.out.print(p);
}
}
D. Compile error - static variable must be initialized before use. E. None of these
Answer: Option A
A. 790 B. 700
Answer: Option D
Answer: Option A
A. 14 21 B. 14 13
Answer: Option C
Answer: Option C
Answer: Option D
E. None of these
Answer: Option C
A. 4 B. 5 C. 12 D. 11
E. None of these
Answer: Option B
1. In Java arrays are
Answer: Option A
Answer: Option B
A. 0
Answer: Option A
A. The program has a compile error because the size of the array wasn't specified when
declaring the array.
B. The program has a runtime error because the array elements are not initialized.
D. The program has a runtime error because the array element x[0] is not defined.
Answer: Option C
A. 0 B. 1
C. 2 D. 3 E. 4
Answer: Option B
Answer: Option B
7. Determine output:
x = new int[2];
A. 1234 B. 0000
C. 12 D. 00 E. None of these
Answer: Option C
A. The code has compile errors because the variable arr cannot be changed once it is
assigned.
B. The code has runtime errors because the variable arr cannot be changed once it is
assigned.
C. The code can compile and run fine. The second line assigns a new array to arr.
D. The code has compile errors because we cannot assign a different size array to arr.
Answer: Option C
A. The program has a compile error because new int[2<sp< label=""> </sp<>
D. a[1] is 1
Answer: Option C
10. When you pass an array to a method, the method receives ________ .
Answer: Option C
11. What would be the result of attempting to compile and run the following code?
A. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and
it should be replaced by {1, 2, 3}.
B. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it
should be replaced by new double[3]{1, 2, 3};
C. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it
should be replaced by new double[]{1.0, 2.0, 3.0};
Answer: Option D
Answer: Option D
Answer: Option D
14. What is the value of a[1] after the following code is executed?
A. 0 B. 1 C. 2
D. 3 E. 4
Answer: Option B
Answer: Option B
class LogicalCompare{
public static void main(String args[]){
String str1 = new String("OKAY");
String str2 = new String(str1);
System.out.println(str1 == str2);
}
}
A. true B. false C. 0
Answer: Option B
D. true true
Answer: Option D
4. Determine output:
A. true B. false C. 0
Answer: Option A
A. Throws an exception as string and int are not compatible for addition
B. hellow9 C. 9hellow
Answer: Option B
A. java.lang.String B. java.lang.Object
Answer: Option B
D. 1 E. -1
Answer: Option C
A. abc B. bc C. bcd
Answer: Option B
A. true B. false C. 1
D. -1 E. 0
Answer: Option D
10. What will be the output of the following program?
Answer: Option C
Answer: Option B
D. java.string
Answer: Option B
D. Compilation error
Answer: Option A
A. 4 B. 3 C. 2 D. None of this
Answer: Option B
A. 2 B. 7 C. 9 D. 11
E. None of this
Answer: Option D
Answer: Option A
A. true,true B. false,true
Answer: Option D
Answer: Option A
Answer: Option E
1. Determine output:
E. 6
Answer: Option E
2. In java, ............ can only test for equality, where as .......... can evaluate any type of the
Boolean expression.
D. continue, if
Answer: Option A
A. 06172838 B. 06172839
Answer: Option A
class Test{
public static void main(String args[]){
int x=7;
if(x==2); // Note the semicolon
System.out.println("NumberSeven");
System.out.println("NotSeven");
}
}
E. 7
Answer: Option A
5. Determine output:
A. 10 B. 11 C. 9 D. 20
E. None of these
Answer: Option A
D. Runtime Error
Answer: Option C
A. 1 B. 2 C. 3 D. 4 E. 0
Answer: Option B
char ch = 'a';
switch (ch){
case 'a':
case 'A': System.out.print(ch); break;
case 'b':
case 'B': System.out.print(ch); break;
case 'c':
case 'C': System.out.print(ch); break;
case 'd':
case 'D': System.out.print(ch);
}
A. abcd B. aa C. a D. ab E. abc
Answer: Option C
9. How many times will the following code print "Welcome to Examveda"?
int count = 0;
do {
System.out.println("Welcome to Examveda");
count++;
} while (count < 10);
A. 8 B. 9 C. 10 D. 11 E. 0
Answer: Option C
10. Choose the correct statement in context of the following program code.
A. The program has a compile error because the adjustment is missing in the for loop.
B. The program has a compile error because the control variable in the for loop cannot be of
the double type.
C. The program runs in an infinite loop because d<10 would always be true.
D. The program compiles and runs fine.
Answer: Option D
Answer: Option D
To view a Sol
A. 1231 B. 1232
Answer: Option C
A. 0 B. 1 C. 2 D. 3 E. 4
Answer: Option B
14. What will be the result of compiling and runnig the following code:
Answer: Option A
15. What all gets printed when the following program is compiled and run.
A. 0 B. 1 C. 2 D. 3 E. 12
Answer: Option E
16. What all gets printed when the following program is compiled and run?
A. 0 B. 1 C. 2
D. The program does not compile because of statement "i=++i;" E. None of these
Answer: Option C
A. 1 B. 2 C. -1 D. 0
E. None of these
Answer: Option D
Answer: Option C
1. int i = 10;
2. while(i++ <= 10){
3. i++;
4. }
5. System.out.print(i);
A. 10 B. 11 C. 12 D. 13
Answer: Option D