JAVA PRO192 sanfoundry
int arr[] = int [5] new
Which of these is an incorrect array declaration? a) int arr[] = new int[5] b) int [] arr = new int[5] c) int arr[] arr = new int[5] d) int arr[] = int [5] new
0x99fffL
Which of these is data type long literal? a) 0x99fffL b) ABCDEFG c) 0x99fffa d) 99671246
"Hello world"
Which of these is incorrect string literal? a) "Hello World" b) "Hello\nWorld" c) "\"Hello World"" d) "Hello world"
Row
Which of these is necessary to specify at time of array initialization? a) Row b) Column c) Both Row and Column d) None of the mentioned
<=
Which of these is not a bitwise operator? a) & b) &= c) |= d) <=
Boolean
Which of these is returned by greater than, <, and equal to, ==, operator? a) Integers b) Floating - point numbers c) Boolean d) None of the mentioned
continue
Which of these jump statements can skip processing remainder of code in its body for a particular iteration? a) break b) return c) exit d) continue
class
Which of these keywords is used to make a class? a) class b) struct c) int d) None of the mentioned
ASCII and ISO-LATIN1
Which of these occupy first 0 to 127 in Unicode character set used for characters in Java? a) ASCII b) ISO-LATIN-1 c) None of the mentioned d) ASCII and ISO-LATIN1
new
Which of these operators is used to allocate memory for an object? a) malloc b) alloc c) new d) give
new
Which of these operators is used to allocate memory to array variable in Java? a) malloc b) alloc c) new d) new malloc
switch
Which of these selection statements test only for equality? a) if b) switch c) if & switch d) None of the mentioned
two case constants in the same switch can have identical values.
Which of these statement is correct? a) switch statement is more efficient than a set of nested ifs. b) two case constants in the same switch can have identical values. c) switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression. d) it is possible to create a nested switch statements.
true and false are non numeric values
Which of these statement is correct? a) true and false are numeric values 1 and 0. b) true and false are numeric values 0 and 1. c) true is any non zero value and false is 0. d) true and false are non numeric values
Every class must contain a main() method.
Which of these statement is incorrect? a) Every class must contain a main() method. b) Applets do not require a main() method at all. c) There can be only one main() method in a program. d) main() method must be made public.
None
Which of these statements are incorrect? a) Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms. b) Assignment operators run faster than their equivalent long forms. c) Assignment operators can be used only with numeric and character data type. d) None
5.640000000000001 5
class Modulus { public static void main(String args[]) { double a = 25.64; int b = 25; a = a % 10; b = b % 10; System.out.println(a + " " + b); } } a) 5.640000000000001 5 b) 5.640000000000001 5.0 c) 5 5 d) 5 5.640000000000001
3 4 4
class Output { public static void main(String args[]) { int a = 1; int b = 2; int c; int d; c = ++b; d = a++; c++; b++; ++a; System.out.println(a + " " + b + " " + c); } } a) 3 2 4 b) 3 2 3 c) 2 3 4 d) 3 4 4
10
class Output { public static void main(String args[]) { int a = 5; int b = 10; first: { second: { third: { if (a == b >> 1) break second; } System.out.println(a); } System.out.println(b); } } } a) 5 10 b) 10 5 c) 5 d) 10
11 10
class Output { public static void main(String args[]) { int x , y; x = 10; x++; --x; y = x++; System.out.println(x + " " + y); } } a) 11 11 b) 10 10 c) 11 10 d) 10 11
Compilation Error
static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } a) 1 b) 2 c) Runtime Error d) Compilation Error
Both Integers and floating - point numbers.
Modulus operator, %, can be applied to which of these? a) Integers b) Floating - point numbers c) Both Integers and floating - point numbers. d) None of the mentioned
31
On applying Left shift operator, <<, on an integer bits are lost one they are shifted past which position bit? a) 1 b) 32 c) 33 d) 31
this
Which keyword is used by method to refer to the object that invoked it? a) import b) catch c) abstract d) this
main method
Which method can be defined only once in a program? a) main method b) finalize method c) static method d) private method
&&
4. Which of these operators can skip evaluating right hand operand? a) ! b) | c) & d) &&
True & False
Which of these values can a boolean variable contain? a) True & False b) 0 & 1 c) Any integer value d) true
int
An expression involving byte, int, and literal numbers is promoted to which of these? a) int b) long c) byte d) float
1
Decrement operator, -, decreases value of variable by what number? a) 1 b) 2 c) 3 d) 4
all of the mentioned
Literal can be of which of these data types? a) integer b) float c) boolean d) all of the mentioned
L and I
Literals in java must be preceded by which of these? a) L b) l c) D d) L and I
method overloading
What is process of defining two or more methods within same class that have same name but different parameters declaration? a) method overloading b) method overriding c) method hiding d) None of the mentioned
-32768 to 32767
What is the numerical range of a char in Java?
0 to 65535
What is the numerical range of a char in Java?
Division operator, /, has higher precedence than multiplication operator.
Which of these statements are incorrect? a) Equal to operator has least precedence. b) Brackets () have highest precedence. c) Division operator, /, has higher precedence than multiplication operator. d) Addition operator, +, and subtraction operator have equal precedence.
boolean b3 = false
Which one is a valid declaration of a boolean? a) boolean b1 = 1; b) boolean b2 = 'false'; c) boolean b3 = false; d) boolean b4 = 'true'
None of the mentioned
Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed? a) delete b) free c) new d) None of the mentioned
~
Which operator is used to invert all the digits in binary representation of a number? a) ~ b) <<< c) >>> d) ^
>>
Which right shift operator preserves the sign of the value? a) << b) >> c) <<= d) >>=
1 3 5 7 9
lass jump_statments { public static void main(String args[]) { int x = 2; int y = 0; for ( ; y < 10; ++y) { if (y % x == 0) continue; else if (y == 8) break; else System.out.print(y + " "); } } } a) 1 3 5 7 b) 2 4 6 8 c) 1 3 5 7 9 d) 1 2 3 4 5 6 7 8 9
Compilation error
public static void main(String args[]) { int x = 9; if (x == 9) { int x = 8; System.out.println(x); } } a) 9 b) 8 c) Compilation error d) Runtime error
All statements are correct.
Which of the following are legal lines of Java code? 1. int w = (int)888.8; 2. byte x = (byte)100L; 3. long y = (byte)100; 4. byte z = (byte)100L; a) 1 and 2 b) 2 and 3 c) 3 and 4 d) All statements are correct.
finalize() method is called when a object goes out of scope and is no longer needed.
Which of the folowing stements are incorrect? a) Default constructor is called at the time of declaration of the object if a constructor has not been defined. b) Constructor can be parameterized. c) finalize() method is called when a object goes out of scope and is no longer needed. d) finalize() method must be declared protected.
if()
Which of these are selection statements in Java? a) if() b) for() c) continue d) break
All of the mentioned
Which of these can be overloaded? a) Methods b) Constructors c) All of the mentioned d) None of the mentioned
Integer or Boolean
Which of these can be returned by the operator & ? a) Integer b) Boolean c) Character d) Integer or Boolean
keyword
Which of these can not be used for a variable name in Java? a) identifier b) keyword c) identifier & keyword d) None of the mentioned
UNICODE
Which of these coding types is used for data type characters in Java? a) ASCII b) ISO-LATIN-1 c) UNICODE d) None of the mentioned
()
Which of these have highest precedence? a) () b) ++ c) * d) >>
It is necessary to use new operator to initialize an array.
Which of these is an incorrect Statement? a) It is necessary to use new operator to initialize an array. b) Array can be initialized using comma separated expressions surrounded by curly braces. c) Array can be initialized when they are declared. d) None of the mentioned
3.4e-038
Which of these literals can be contained in a data type float variable? a) 1.7e-308 b) 3.4e-038 c) 1.7e+308 d) 3.4e-050
The right shift operator automatically fills the higher order bits with 0.
Which of these statements are incorrect? a) The left shift operator, <<, shifts all of the bite in a value to the left specified number of times. b) The right shift operator, >>, shifts all of the bite in a value to the right specified number of times. c) The left shift operator can be used as an alternative to multiplying by 2. d) The right shift operator automatically fills the higher order bits with 0.
3 & 2
With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? 1. x++; 2. x = x + 1; 3. x += 1; 4. x =+ 1; a) 1, 2 & 3 b) 1 & 4 c) 1, 2, 3 & 4 d) 3 & 2
true
class equality { int x; int y; boolean isequal(){ return(x == y); } } class Output { public static void main(String args[]) { equality obj = new equality(); obj.x = 5; obj.y = 5; System.out.println(obj.isequal()); } }
Box obj = new Box();
Which of the following is a valid declaration of an object of class Box? a) Box obj = new Box(); b) Box obj = new Box; c) obj = new Box(); d) new Box obj;
do-while
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false? a) do-while b) while c) for d) None of the mentioned
1, 2 & 3
Which of the following operators can operate on a boolean variable? 1. && 2. == 3. ?: 4. += a) 3 & 2 b) 1 & 4 c) 1, 2 & 4 d) 1, 2 & 3
false
class booloperators { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; System.out.println((var2 & var2)); } } a) 0 b) 1 c) true d) false
25
class box { int width; int height; int length; int volume; void volume() { volume = width*height*length; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(); System.out.println(obj.volume); } }
void
What is the return type of a method that does not returns any value? a) int b) float c) void d) double
double
Which data type value is returned by all transcendental math functions? a) int b) float c) double d) long
finalize()
Which function is used to perform some action when the object is to be destroyed? a) finalize() b) delete() c) main() d) None of the mentioned
Both Numeric & Characters
Which of the following can be operands of arithmetic operators? a) Numeric b) Boolean c) Characters d) Both Numeric & Characters
constructor
Which of the following is a method having same name as that of it's class? a) finalize b) delete c) class d) constructor
constructor
Which of the following is a method having same name as that of its class? a) finalize b) delete c) class d) constructor
1
class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } }
1.5 1
class increment { public static void main(String args[]) { double var1 = 1 + 5; double var2 = var1 / 4; int var3 = 1 + 5; int var4 = var3 / 4; System.out.print(var2 + " " + var4); } } a) 1 1 b) 0 1 c) 1.5 1 d) 1.5 1.0
32
class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } a) 25 b) 24 c) 32 d) 33
40
class evaluate { public static void main(String args[]) { int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); } } a) 38 b) 39 c) 40 d) 41
true
class mainclass { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; if (var1) System.out.println(var1); else System.out.println(var2); } } a) 0 b) 1 c) true d) false
66
class mainclass { public static void main(String args[]) { char a = 'A'; a++; System.out.print((int)a); } } a) 66 b) 67 c) 65 d) 64
Function overloading
What is the process of defining more than one method in a class differentiated by method signature? a) Function overriding b) Function overloading c) Function doubling d) None of the mentioned
-128 to 127
What is the range of data type byte in Java?
None of the mentioned
What is the return type of Constructors? a) int b) float c) void d) None of the mentioned
NULL
What is the stored in the object obj in following lines of code? box obj; a) Memory address of allocated memory of object. b) NULL c) Any arbitrary pointer d) Garbage
Boolean
What should be expression1 evaluate to in using ternary operator as in this line? expression1 ? expression2 : expression3 a) Integer b) Floating - point numbers c) Boolean d) None of the mentioned
Public method is accessible to all other classes in the hierarchy
Which of the following statements is correct? a) Public method is accessible to all other classes in the hierarchy b) Public method is accessible only to subclasses of its parent class c) Public method can only be called by object of its class. d) Public method can be accessed by calling object of the public class.
10
class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } } a) 11 b) 10 c) 13 d) 14
Compilation error
class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } a) 5 6 5 6 b) 5 6 5 c) Runtime error d) Compilation error
1 -> 2 -> 3
What is the order of precedence (highest to lowest) of following operators? 1. & 2. ^ 3. ?: a) 1 -> 2 -> 3 b) 2 -> 1 -> 3 c) 3 -> 2 -> 1 d) 2 -> 3 -> 1
Boolean
What is the output of relational operators? a) Integer b) Boolean c) Characters d) Double
Garbage value
What will this code print? int arr[] = new int [5]; System.out.print(arr); a) 0 b) value stored in arr[0]. c) 00000 d) Garbage value
6 5
class area { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; } } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + " " + obj.width); } } a) 0 0 b) 5 6 c) 6 5 d) 5 5
error
class area { int width; int length; int volume; area() { width=5; length=6; } void volume() { volume = width*length*height; } } class cons_method { public static void main(String args[]) { area obj = new area(); obj.volume(); System.out.println(obj.volume); } } a) 0 b) 1 c) 30 d) error
301.5656
class area { public static void main(String args[]) { double r, pi, a; r = 9.8; pi = 3.14; a = pi * r * r; System.out.println(a); } } a) 301.5656 b) 301 c) 301.56 d) 301.56560000
i i i i i i i i i i
class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + ""); } } } a) 1 2 3 4 5 6 7 8 9 10 b) 0 1 2 3 4 5 6 7 8 9 10 c) i j k l m n o p q r d) i i i i i i i i i i
1 2 3 4 5
class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i/2; array_variable[i]++; System.out.print(array_variable[i] + " "); i++; } } } a) 0 2 4 6 8 b) 1 2 3 4 5 c) 0 1 2 3 4 5 6 7 8 9 d) 1 2 3 4 5 6 7 8 9 10
0 2 4 6 8
class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i; System.out.print(array_variable[i] + " "); i++; } } } a) 0 2 4 6 8 b) 1 3 5 7 9 c) 0 1 2 3 4 5 6 7 8 9 d) 1 2 3 4 5 6 7 8 9 10
9
class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 5); } } a) 8 b) 9 c) 10 d) 11
i i i i i
class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + "" ); i++; } } } a) i i i i i b) 0 1 2 3 4 c) i j k l m d) None of the mentioned
65 97
class asciicodes { public static void main(String args[]) { char var1 = 'A'; char var2 = 'a'; System.out.println((int)var1 + " " + (int)var2); } } a) 162 b) 65 97 c) 67 95 d) 66 98
16.46666666666667
class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6); } } a) 16.34 b) 16.566666644 c) 16.46666666666667 d) 16.46666666666666
42 -43
class bitwise_operator { public static void main(String args[]) { int var1 = 42; int var2 = ~var1; System.out.print(var1 + " " + var2); } } a) 42 42 b) 43 43 c) 42 -43 d) 42 43
7 2
class bitwise_operator { public static void main(String args[]) { int a = 3; int b = 6; int c = a | b; int d = a & b; System.out.println(c + " " + d); } } a) 7 2 b) 7 7 c) 7 5 d) 5 2
6
class box { int width; int height; int length; int volume; void volume(int height, int length, int width) { volume = width*height*length; } } class Prameterized_method{ public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(3,2,1); System.out.println(obj.volume); } }
Garbage value
class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj = new box(); System.out.println(obj); } } a) 0 b) 1 c) Runtime error d) Garbage value
1
class box { int width; int height; int length; } class mainclass { public static void main(String args[]) { box obj1 = new box(); box obj2 = new box(); obj1.height = 1; obj1.length = 2; obj1.width = 1; obj2 = obj1; System.out.println(obj2.height); } }
39 44
class conversion { public static void main(String args[]) { double a = 295.04; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); } } a) 38 43 b) 39 44 c) 295 300 d) 295.04 300
5.0
class dynamic_initialization { public static void main(String args[]) { double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); } } a) 5.0 b) 25.0 c) 7.0 d) Compilation Error