0% found this document useful (0 votes)
12 views68 pages

Java Multiple Choice Questions

The document contains a series of multiple-choice questions related to Java programming concepts, covering topics such as data types, operators, control structures, and code outputs. Each question presents a scenario or concept with four answer options, testing the reader's knowledge of Java syntax and behavior. The questions range from basic data type ranges to more complex code execution outputs.

Uploaded by

65eomjadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views68 pages

Java Multiple Choice Questions

The document contains a series of multiple-choice questions related to Java programming concepts, covering topics such as data types, operators, control structures, and code outputs. Each question presents a scenario or concept with four answer options, testing the reader's knowledge of Java syntax and behavior. The questions range from basic data type ranges to more complex code execution outputs.

Uploaded by

65eomjadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Multiple Choice Questions

1. What is the range of short data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

2. What is the range of byte data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned

[Link] expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float

[Link] of these literals can be contained in float data type variable?


a) -1.7e+308
b) -3.4e+038
c) +1.7e+308
d) -3.4e+050

5. Which data type value is returned by all transcendental math functions?


a) int
b) float
c) double
d) long

[Link] will be the output of the following Java code?

class increment {
public static void main(String args[])
{
int g = 3;
[Link](++g * 8);
}
}
a) 25
b) 24
c) 32
d) 33

7. What will be the output of the following Java code?

class area {
public static void main(String args[])
{
double r, pi, a;
r = 9.8;
pi = 3.14;
a = pi * r * r;
[Link](a);
}
}
a) 301.5656
b) 301
c) 301.56
d) 301.56560000

8. What is the numerical range of a char data type in Java?


a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535

[Link] 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

10. Which of these values can a boolean variable contain?


a) True & False
b) 0 & 1
c) Any integer value
d) true

11. 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’

[Link] will be the output of the following Java program?

class mainclass {
public static void main(String args[])
{
char a = 'A';
a++;
[Link]((int)a);
}
}
a) 66
b) 67
c) 65
d) 64
13. Which of these is long data type literal?
a) 0x99fffL
b) ABCDEFG
c) 0x99fffa
d) 99671246

14. Which of these can be returned by the operator &?


a) Integer
b) Boolean
c) Character
.d) Integer or Boolean

15. Literal can be of which of these data types?


a) integer
b) float
c) boolean
d) all of the mentioned

[Link] of these can not be used for a variable name in Java?


a) identifier
b) keyword
c) identifier & keyword
d) none of the mentioned

17. Which of these is necessary condition for automatic type conversion in Java?
a) The destination type is smaller than source type
.b) The destination type is larger than source type
c) The destination type can be larger or smaller than source type
d) None of the mentioned

18. If an expression contains double, int, float, long, then the whole expression will be promoted into
which of these data types?
a) long
b) int
c) double
d) float

19. What will be the output of the following Java code?

class char_increment
{
public static void main(String args[])
{
char c1 = 'D';
char c2 = 84;
c2++;
c1++;
[Link](c1 + " " + c2);
}
}
a) E U
b) U E
c) V E
d) U F

20. Which of these operators is used to allocate memory to array variable in Java?
a) malloc
b) alloc
c) new
d) new malloc

21. Which of these is an incorrect array declaration?


a) int arr[] = new int[5]
b) int [] arr = new int[5]
c) int arr[] = new int[5]
d) int arr[] = int [5] new

22. 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

23. Which of the following can be operands of arithmetic operators?


a) Numeric
b) Boolean
c) Characters
d) Both Numeric & Characters

24. 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

25. Decrement operator, −−, decreases the value of variable by what number?
a) 1
b) 2
c) 3
d) 4

26. What will be the output of the following Java program?

class increment
{
public static void main(String args[])
{
double var1 = 1 + 5;
double var2 = var1 / 4;
int var3 = 1 + 5;
int var4 = var3 / 4;
[Link](var2 + " " + var4);

}
}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0

27. What will be the output of the following Java program?

class Modulus
{
public static void main(String args[])
{
double a = 25.64;
int b = 25;
a = a % 10;
b = b % 10;
[Link](a + " " + b);
}
}
a) 5.640000000000001 5
b) 5.640000000000001 5.0
c) 5 5
d) 5 5.640000000000001

28. Can 8 byte long data type be automatically type cast to 4 byte float data type?
a) True
b) False

29. What will be the output of the following Java program?

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;
[Link](a + " " + b + " " + c);
}
}
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4

30. What is the output of relational operators?


a) Integer
b) Boolean
c) Characters
d) Double

31. Which of these is returned by “greater than”, “less than” and “equal to” operators?
a) Integers
b) Floating – point numbers
c) Boolean
d) None of the mentioned

32. 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

33. Which of these operators can skip evaluating right hand operand?
a) !
b) |
c) &
d) &&

34. Which of these statements 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

35. What will be the output of the following Java code?

class Relational_operator
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
[Link](var1 > var2);
}
}
a) 1
b) 0
c) true
d) false

36. What will be the output of the following Java code?

class bool_operator
{
public static void main(String args[])
{
boolean a = true;
boolean b = !true;
boolean c = a | b;
boolean d = a & b;
boolean e = d ? b : c;
[Link](d + " " + e);
}
}
a) false false
b) true ture
c) true false
d) false true

37. What will be the output of the following Java code?

class ternary_operator
{
public static void main(String args[])
{
int x = 3;
int y = ~ x;
int z;
z = x > y ? x : y;
[Link](z);
}
}
a) 0
b) 1
c) 3
d) -4

38. What will be the output of the following Java code?

class Output
{
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
[Link](y);
else
[Link](++y);
}
}
a) 1
b) 2
c) Runtime error owing to division by zero in if condition
d) Unpredictable behavior of program

[Link] will be the output of the following Java code?

class Output
{
public static void main(String args[])
{
boolean a = true;
boolean b = false;
boolean c = a ^ b;
[Link](!c);
}
}
a) 0
b) 1
c) false
d) true

40. Which of these have highest precedence?


a) ()
b) ++
c) *
d) >>

41. 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

42. What is the value stored in x in the following lines of Java code?

int x, y, z;
x = 0;
y = 1;
x = y = z = 8;
a) 0
b) 1
c) 9
d) 8

43. 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

44. 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

45. What will be the output of the following Java code?

class operators
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
int var3;
var3 = ++ var2 * var1 / var2 + var2;
[Link](var3);
}
}
a) 10
b) 11
c) 12
d) 56

46. What will be the output of the following Java code?

class operators
{
public static void main(String args[])
{
int x = 8;
[Link](++x * 3 + " " + x);
}
}
a) 24 8
b) 24 9
c) 27 8
d) 27 9
47. What will be the output of the following Java code?

class Output
{
public static void main(String args[])
{
int x=y=z=20;

}
}
a) compile and runs fine
b) 20
c) run time error
d) compile time error

48. Which of these lines of Java code will give better performance?

1. a | 4 + c >> b & 7;
2. (a | ((( 4 * c ) >> b ) & 7 ))
a) 1 will give better performance as it has no parentheses
b) 2 will give better performance as it has parentheses
c) Both 1 & 2 will give equal performance
d) Dependent on the computer system

49. What will be the output of the following Java program?

class Output
{
public static void main(String args[])
{
int a,b,c,d;
a=b=c=d=20
a+=b-=c*=d/=20
[Link](a+" "+b+" "+c+" "+d);

}
}
a) compile time error
b) runtime error
c) a=20 b=0 c=20 d=1
d) none of the mentioned

50. Which of these selection statements test only for equality?


a) if
b) switch
c) if & switch
d) none of the mentioned

51. Which of these are selection statements in Java?


.a) if()
b) for()
c) continue
d) break

52. 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

53. Which of these jump statements can skip processing the remainder of the code in its body for a
particular iteration?
a) break
b) return
c) exit
d) continue

54. Which of this statement is incorrect?


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

55. What will be the output of the following Java program?

class selection_statements
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
[Link](var2);
else
[Link](++var2);
}
}
a) 1
b) 2
c) 3
d) 4

56. What will be the output of the following Java program?

class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
[Link](sum);
}
}
a) 5
b) 6
c) 14
d) compilation error

57. What will be the output of the following Java program?

class 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
[Link](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

58. The while loop repeats a set of code while the condition is not met?
a) True
b) False

59. What is true about a break?


a) Break stops the execution of entire program
.b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of next iteration
d) Break halts the execution of the loop for certain time frame

60. What is true about do statement?


a) do statement executes the code of a loop at least once
b) do statement does not get execute if condition is not matched in the first iteration
c) do statement checks the condition at the beginning of the loop
d) do statement executes the code more than once always
[Link] of the following is used with the switch statement?
a) Continue
b) Exit
c) break
d) do

[Link] of the following is not a decision making statement?


a) if
b) if-else
c) switch
d) do-while

63. Which of the following is not a valid jump statement?


a) break
.b) goto
c) continue
d) return

64. From where break statement causes an exit?


a) Only from innermost loop
b) Terminates a program
c) Only from innermost switch
.d) From innermost loops or switches

[Link] of the following is not a valid flow control statement?


.a) exit()
b) break
c) continue
d) return

OOPS
1. Which of the following is not OOPS concept in Java?
a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation

2. Which of the following is a type of polymorphism in Java?


a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism

3. When does method overloading is determined?


a) At run time
b) At compile time
c) At coding time
d) At execution time

4. When Overloading does not occur?


a) More than one method with same name but different method signature and different number or
type of parameters
b) More than one method with same name, same signature but different number of signature
c) More than one method with same name, same signature, same number of parameters but
different type
d) More than one method with same name, same number of parameters and type but different
signature

5. Which concept of Java is a way of converting real world objects in terms of class?
a) Polymorphism
b) Encapsulation
c.) Abstraction
d) Inheritance

6. Which concept of Java is achieved by combining methods and attribute into a class?
a) Encapsulation
b) Inheritance
c) Polymorphism
d) Abstraction

7. What is it called if an object has its own lifecycle and there is no owner?
a) Aggregation
b) Composition
c) Encapsulation
d.) Association

8. What is it called where child object gets killed if parent object is killed?
a) Aggregation
b.) Composition
c) Encapsulation
d) Association

9. What is it called where object has its own lifecycle and child object cannot belong to another
parent object?
a.) Aggregation
b) Composition
c) Encapsulation
d) Association

10. Method overriding is combination of inheritance and polymorphism?


a) True
b) false
JVM/JDK

1. Which component is used to compile, debug and execute java program?


a) JVM
b.) JDK
c) JIT
d) JRE

2. Which component is responsible for converting bytecode into machine specific code?
a.) JVM
b) JDK
c) JIT
d) JRE

3. Which component is responsible to run java program?


a) JVM
b) JDK
c) JIT
d.) JRE

4. Which component is responsible to optimize bytecode to machine code?


a) JVM
b) JDK
c.) JIT
d) JRE

5. Which statement is true about java?


a) Platform independent programming language
b) Platform dependent programming language
c) Code dependent programming language
d) Sequence dependent programming language

6. Which of the below is invalid identifier with the main method?


a) public
b) static
c) private
d) final

7. What is the extension of java code files?


a) .class
b) .java
c) .txt
d) .js

8. What is the extension of compiled java classes?


a) .class
b) .java
c) .txt
d) .js

9. How can we identify whether a compilation unit is class or interface from a .class file?
a.) Java source file header
b) Extension of compilation unit
c) We cannot differentiate between class and interface
d) The class or interface name should be postfixed with unit type

10. What is use of interpreter?


a) They convert bytecode to machine language code
b.) They read high level code and execute them
c) They are intermediated between JIT and JVM
d) It is a synonym for JIT

class in Java

1. What is the stored in the object obj in following lines of Java code?

box obj;
a) Memory address of allocated memory of object
b) NULL
c) Any arbitrary pointer
d) Garbage

2. Which of these keywords is used to make a class?


a) class
b) struct
c) int
d) none of the mentioned

3. 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;

4. Which of these operators is used to allocate memory for an object?


a) malloc
b) alloc
c) new
d) give

5. 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
6. What will be the output of the following Java program?

class main_class
{
public static void main(String args[])
{
int x = 9;
if (x == 9)
{
int x = 8;
[Link](x);
}
}
}
a) 9
b) 8
c) Compilation error
d) Runtime error

7. 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

8. What will be the output of the following Java program?

class box
{
int width;
int height;
int length;
}
class mainclass
{
public static void main(String args[])
{
box obj = new box();
[Link] = 10;
[Link] = 2;
[Link] = 10;
int y = [Link] * [Link] * [Link];
[Link](y);
}
}
a) 12
b) 200
c) 400
d) 100

9. What will be the output of the following Java program?

class box
{
int width;
int height;
int length;
}
class mainclass
{
public static void main(String args[])
{
box obj1 = new box();
box obj2 = new box();
[Link] = 1;
[Link] = 2;
[Link] = 1;
obj2 = obj1;
[Link]([Link]);
}
}
a) 1
b) 2
c) Runtime error
d) Garbage value

10. What will be the output of the following Java program?


class box
{
int width;
int height;
int length;
}
class mainclass
{
public static void main(String args[])
{
box obj = new box();
[Link](obj);
}
}
a) 0
b) 1
c) Runtime error
d) classname@hashcode in hexadecimal form

Methods/Functions:

1. What is the return type of a method that does not return any value?
a) int
b) float
c) void
d) double

2. 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

3. Which of the following is a method having same name as that of it’s class?
a) finalize
b) delete
c) class
d) constructor

4. Which method can be defined only once in a program?


a) main method
b) finalize method
c) static method
d) private method

5. Which of this statement is incorrect?


a) All object of a class are allotted memory for the all the variables defined in the class
b) If a function is defined public it can be accessed by object of other class by inheritation
c) main() method must be made public
d) All object of a class are allotted memory for the methods defined in the class
6. What will be the output of the following Java program?

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();
[Link] = 1;
[Link] = 5;
[Link] = 5;
[Link](3,2,1);
[Link]([Link]);
}
}
a) 0
b) 1
c) 6
d) 25
7. What will be the output of the following Java program?

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;
[Link]([Link]());
}
}
a) false
b) true
c) 0
d) 1

8. What will be the output of the following Java program?

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();
[Link] = 1;
[Link] = 5;
[Link] = 5;
[Link]();
[Link]([Link]);
}
}
a) 0
b) 1
c) 25
d) 26

9. In the following Java code, which call to sum() method is appropriate?

class Output
{

public static int sum(int ...x)


{
return;
}
static void main(String args[])
{
sum(10);
sum(10,20);
sum(10,20,30);
sum(10,20,30,40);
}
}
a) only sum(10)
b) only sum(10,20)
c) only sum(10) & sum(10,20)
d) all of the mentioned

10. What will be the output of the following Java program?

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();
[Link]();
[Link]([Link]);
}
}
a) 0
b) 1
c) 30
d) error

1. What is the return type of Constructors?


a) int
b) float
c) void
d) none of the mentioned

2. Which keyword is used by the method to refer to the object that invoked it?
a) import
b) catch
c) abstract
d) this

3. Which of the following is a method having same name as that of its class?
a) finalize
b) delete
c) class
d) constructor

4. 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

5. 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

6. What will be the output of the following Java code?

class box
{
int width;
int height;
int length;
int volume;
box()
{
width = 5;
height = 5;
length = 6;
}
void volume()
{
volume = width*height*length;
}
}
class constructor_output
{
public static void main(String args[])
{
box obj = new box();
[Link]();
[Link]([Link]);
}
}
a) 100
b) 150
c) 200
d) 250

7. What will be the output of the following Java code?

class San
{
San()throws IOException
{
}

}
class Foundry extends San
{
Foundry()
{

}
public static void main(String[]args)
{

}
}
a) compile time error
b) run time error
c) compile and runs fine
d) unreported exception [Link] in default constructor

8. What will be the output of the following Java code?

class box
{
int width;
int height;
int length;
int volume;
void finalize()
{
volume = width*height*length;
[Link](volume);
}
protected void volume()
{
volume = width*height*length;
[Link](volume);
}
}
class Output
{
public static void main(String args[])
{
box obj = new box();
[Link]=5;
[Link]=5;
[Link]=6;
[Link]();
}
}
a) 150
b) 200
c) Run time error
d) Compilation error

9. Which of the following statements are incorrect?


a) default constructor is called at the time of object declaration
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

10. What will be the output of the following Java code?

class area
{
int width;
int length;
int area;
void area(int width, int length)
{
[Link] = width;
[Link] = length;
}

}
class Output
{
public static void main(String args[])
{
area obj = new area();
[Link](5 , 6);
[Link]([Link] + " " + [Link]);
}
}
a) 0 0
b) 5 6
c) 6 5
d) 5 5

1. What is true about private constructor?


a) Private constructor ensures only one instance of a class exist at any point of time
b) Private constructor ensures multiple instances of a class exist at any point of time
c) Private constructor eases the instantiation of a class
d) Private constructor allows creating objects in other classes

2. What would be the behaviour if this() and super() used in a method?


a) Runtime error
b) Throws exception
c) compile time error
d) Runs successfully

3. What is false about constructor?


a) Constructors cannot be synchronized in Java
b) Java does not provide default copy constructor
c) Constructor can't be overloaded
d) “this” and “super” can be used in a constructor

4. What is true about [Link]()?


a) [Link] calls the constructor
b) [Link] is same as new operator
c) [Link] needs to have matching constructor
d) [Link] creates object if class does not have any constructor

5. What is true about constructor?


a) It can contain return type
b) It can take any number of parameters
c) It can have any non access modifiers
d) Constructor cannot throw an exception

6. Abstract class cannot have a constructor.


a) True
b) False

7. What is true about protected constructor?


a) Protected constructor can be called directly
b) Protected constructor can only be called using super()
c) Protected constructor can be used outside package
d) protected constructor can be instantiated even if child is in a different package

8. What is not the use of “this” keyword in Java?


a) Passing itself to another method
b) Calling another constructor in constructor chaining
c) Referring to the instance variable when local variable has the same name
d) Passing itself to method of the same class

9. What would be the behaviour if one parameterized constructor is explicitly defined?


a) Compilation error
b) Compilation succeeds
c) Runtime error
d) Compilation succeeds but at the time of creating object using default constructor, it throws
compilation error

10. What would be behaviour if the constructor has a return type?


a) Compilation error
b) Runtime error
c) Compilation and runs successfully
d) Only String return type is allowed

1. What is the 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
2. Which of these can be overloaded?
a) Methods
b) Constructors
c) All of the mentioned
d) None of the mentioned

3. Which of these is correct about passing an argument by call-by-value process?


a) Copy of argument is made into the formal parameter of the subroutine
b) Reference to original argument is passed to formal parameter of the subroutine
c) Copy of argument is made into the formal parameter of the subroutine and changes made on
parameters of subroutine have effect on original argument
d) Reference to original argument is passed to formal parameter of the subroutine and changes
made on parameters of subroutine have effect on original argument

4. What is the process of defining a method in terms of itself, that is a method that calls itself?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion

5. What will be the output of the following Java code?

class San
{
public void m1 (int i,float f)
{
[Link](" int float method");
}

public void m1(float f,int i);


{
[Link]("float int method");
}

public static void main(String[]args)


{
San s=new San();
s.m1(20,20);
}
}
a) int float method
b) float int method
c) compile time error
d) run time error

6. What will be the output of the following Java code?

class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a, int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
[Link](6);
[Link](obj.x);
}
}
a) 5
b) 6
c) 7
d) 8

7. What will be the output of the following Java code?

class overload
{
int x;
int y;
void add(int a)
{
x = a + 1;
}
void add(int a , int b)
{
x = a + 2;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 0;
[Link](6, 7);
[Link](obj.x);
}
}
a) 6
b) 7
c) 8
d) 9

8. What will be the output of the following Java code?

class overload
{
int x;
double y;
void add(int a , int b)
{
x = a + b;
}
void add(double c , double d)
{
y = c + d;
}
overload()
{
this.x = 0;
this.y = 0;
}
}
class Overload_methods
{
public static void main(String args[])
{
overload obj = new overload();
int a = 2;
double b = 3.2;
[Link](a, a);
[Link](b, b);
[Link](obj.x + " " + obj.y);
}
}
a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4

9. What will be the output of the following Java code?

class test
{
int a;
int b;
void meth(int i , int j)
{
i *= 2;
j /= 2;
}
}
class Output
{
public static void main(String args[])
{
test obj = new test();
int a = 10;
int b = 20;
[Link](a , b);
[Link](a + " " + b);
}
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20

10. What will be the output of the following Java code?

class test
{
int a;
int b;
test(int i, int j)
{
a = i;
b = j;
}
void meth(test o)
{
o.a *= 2;
O.b /= 2;
}
}
class Output
{
public static void main(String args[])
{
test obj = new test(10 , 20);
[Link](obj);
[Link](obj.a + " " + obj.b);
}
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20

1. Which of these access specifiers must be used for main() method?


a) private
b) public
c) protected
d) none of the mentioned

2. Which of these is used to access a member of class before object of that class is created?
a) public
b) private
c) static
d) protected

3. Which of these is used as a default for a member of a class if no access specifier is used for it?
a) private
b) public
c) public, within its own package
d) protected

4. What is the process by which we can control what parts of a program can access the members of
a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion

5. Which of the following statements are incorrect?


a) public members of class can be accessed by any code in the program
b) private members of class can only be accessed by other members of the class
c) private members of class can be inherited by a subclass, and become protected members in
subclass
d) protected members of a class can be inherited by a subclass, and become private members of the
subclass

6. What will be the output of the following Java code?

class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
}
public class access_specifier
{
public static void main(String args[])
{
access obj = new access();
[Link](2, 3);
[Link](obj.x + " " + obj.y);
}
}
a) 3 3
b) 2 3
c) Runtime Error
d) Compilation Error

7. What will be the output of the following Java code?

class access
{
public int x;
private int y;
void cal(int a, int b)
{
x = a + 1;
y = b;
}
void print()
{
[Link](" " + y);
}
}
public class access_specifier
{
public static void main(String args[])
{
access obj = new access();
[Link](2, 3);
[Link](obj.x);
[Link]();
}
}
a) 2 3
b) 3 3
c) Runtime Error
d) Compilation Error

8. What will be the output of the following Java code?

class static_out
{
static int x;
static int y;
void add(int a, int b)
{
x = a + b;
y = x + b;
}
}
public class static_use
{
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
[Link](a, a + 1);
[Link](5, a);
[Link](obj1.x + " " + obj2.y);
}
}
a) 7 7.4
b) 6 6.4
c) 7 9
d) 9 7

9. Which of these access specifier must be used for class so that it can be inherited by another
subclass?
a) public
b) private
c) protected
d) none of the mentioned

1. Which one of the following is not an access modifier?


a) Public
b) Private
c) Protected
d) Void

2. All the variables of class should be ideally declared as?


a) private
b) public
c) protected
d) default

3. Which of the following modifier means a particular variable cannot be accessed within the
package?
a) private
b) public
c) protected
d) default

4. How can a protected modifier be accessed?


a) accessible only within the class
b) accessible only within package
c) accessible within package and outside the package but through inheritance only
d) accessible by all

5. What happens if constructor of class A is made private?


a) Any class can instantiate objects of class A
b) Objects of class A can be instantiated only within the class where it is declared
c) Inherited class can instantiate objects of class A
d) classes within the same package as class A can instantiate objects of class A

6. All the variables of interface should be?


a) default and final
b) default and static
c) public, static and final
d) protect, static and final

7. What is true of final class?


a) Final class cause compilation failure
b) Final class cannot be instantiated
c) Final class cause runtime failure
d) Final class cannot be inherited

8. How many copies of static and class variables are created when 10 objects are created of a class?
a) 1, 10
b) 10, 10
c) 10, 1
d) 1, 1

9. Can a class be declared with a protected modifier.


a) True
b) False

10. Which is the modifier when there is none mentioned explicitly?


a) protected
b) private
c) public
d) default

1. Arrays in Java are implemented as?


a) class
b) object
c) variable
d) none of the mentioned

2. Which of these keywords is used to prevent content of a variable from being modified?
a) final
b) last
c) constant
d) static

3. Which of these cannot be declared static?


a) class
b) object
c) variable
d) method

4. Which of the following statements are incorrect?


a) static methods can call other static methods only
b) static methods must only access static data
c) static methods can not refer to this or super in any way
d) when object of class is declared, each object contains its own copy of static variables

5. Which of the following statements are incorrect?


a) Variables declared as final occupy memory
b) final variable must be initialized at the time of declaration
c) Arrays in java are implemented as an object
d) All arrays contain an attribute-length which contains the number of elements stored in the array

6. Which of these methods must be made static?


a) main()
b) delete()
c) run()
d) finalize()

7. What will be the output of the following Java program?

class access
{
public int x;
static int y;
void cal(int a, int b)
{
x += a ;
y += b;
}
}
class static_specifier
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
obj1.y = 0;
[Link](1, 2);
obj2.x = 0;
[Link](2, 3);
[Link](obj1.x + " " + obj2.y);
}
}
a) 1 2
b) 2 3
c) 3 2
d) 1 5

8. What will be the output of the following Java program?

class access
{
static int x;
void increment()
{
x++;
}
}
class static_use
{
public static void main(String args[])
{
access obj1 = new access();
access obj2 = new access();
obj1.x = 0;
[Link]();
[Link]();
[Link](obj1.x + " " + obj2.x);
}
}
a) 1 2
b) 1 1
c) 2 2
d) Compilation Error

9. What will be the output of the following Java program?

class static_out
{
static int x;
static int y;
void add(int a , int b)
{
x = a + b;
y = x + b;
}
}
class static_use
{
public static void main(String args[])
{
static_out obj1 = new static_out();
static_out obj2 = new static_out();
int a = 2;
[Link](a, a + 1);
[Link](5, a);
[Link](obj1.x + " " + obj2.y);
}
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7
10. What will be the output of the following Java program?

class Output
{
public static void main(String args[])
{
int arr[] = {1, 2, 3, 4, 5};
for ( int i = 0; i < [Link] - 2; ++i)
[Link](arr[i] + " ");
}
}
a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5

11. What will be the output of the following Java program?

class Output
{
public static void main(String args[])
{
int a1[] = new int[10];
int a2[] = {1, 2, 3, 4, 5};
[Link]([Link] + " " + [Link]);
}
}
a) 10 5
b) 5 10
c) 0 10
d) 0 5

1. String in Java is a?
a) class
b) object
c) variable
d) character array

2. Which of these method of String class is used to obtain character at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()

3. Which of these keywords is used to refer to member of base class from a subclass?
a) upper
b) super
c) this
d) none of the mentioned
4. Which of these method of String class can be used to test to strings for equality?
a) isequal()
b) isequals()
c) equal()
d) equals()

5. Which of the following statements are incorrect?


a) String is a class
b) Strings in java are mutable
c) Every string is an object of class String
d) Java defines a peer class of String, called StringBuffer, which allows string to be altered

6. What will be the output of the following Java program?

class string_demo
{
public static void main(String args[])
{
String obj = "I" + "like" + "Java";
[Link](obj);
}
}
a) I
b) like
c) Java
d) IlikeJava

7. What will be the output of the following Java program?

class string_class
{
public static void main(String args[])
{
String obj = "I LIKE JAVA";
[Link]([Link](3));
}
}
a) I
b) L
c) K
d) E

8. What will be the output of the following Java program?

class string_class
{
public static void main(String args[])
{
String obj = "I LIKE JAVA";
[Link]([Link]());
}
}
a) 9
b) 10
c) 11
d) 12

9. What will be the output of the following Java program?

class string_class
{
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
[Link](obj + " " + obj2);
}
}
a) hello hello
b) world world
c) hello world
d) world hello

10. What will be the output of the following Java program?

class string_class
{
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = "hello";
[Link]([Link](obj1) + " " + [Link](obj2));
}
}
a) false false
b) true true
c) true false
d) false true

1. Which of this method is given parameter via command line arguments?


a) main()
b) recursive() method
c) Any method
d) System defined methods
View Answer

2. Which of these data types is used to store command line arguments?


a) Array
b) Stack
c) String
d) Integer
View Answer

3. How many arguments can be passed to main()?


a) Infinite
b) Only 1
c) System Dependent
d) None of the mentioned
View Answer

4. Which of these is a correct statement about args in the following line of code?

public static void main(String args[])


a) args is a String
b) args is a Character
c) args is an array of String
d) args in an array of Character

5. Can command line arguments be converted into int automatically if required?


a) Yes
b) No
c) Compiler Dependent
d) Only ASCII characters can be converted

6. What will be the output of the following Java program, Command line execution is done as – “java
Output This is a command Line”?

class Output
{
public static void main(String args[])
{
[Link](args[0]);
}
}
a) java
b) Output
c) This
d) is

7. What will be the output of the following Java program, Command line exceution is done as – “java
Output This is a command Line”?

class Output
{
public static void main(String args[])
{
[Link](args[3]);
}
}
a) java
b) is
c) This
d) command

8. What will be the output of the following Java program, Command line execution is done as – “java
Output This is a command Line”?

class Output
{
public static void main(String args[])
{
[Link](args);
}
}
a) This
b) java Output This is a command Line
c) This is a command Line
d) Compilation Error

9. What will be the output of the following Java program, Command line execution is done as – “java
Output command Line 10 A b 4 N”?

class Output
{
public static void main(String args[])
{
[Link]((int)args[2] * 2);
}
}
a) java
b) 10
c) 20
d) b

10. What will be the output of the following Java program, Command line execution is done as –
“java Output command Line 10 A b 4 N”?

class Output
{
public static void main(String args[])
{
[Link](args[6]);
}
}
a) java
b) 10
c) b
d) N

1. Which of this keyword can be used in a subclass to call the constructor of superclass?
a) super
b) this
c) extent
d) extends

2. What is the process of defining a method in a subclass having same name & type signature as a
method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned

3. Which of these keywords can be used to prevent Method overriding?


a) static
b) constant
c) protected
d) final

4. Which of these is correct way of calling a constructor having no parameters, of superclass A by


subclass B?
a) super(void);
b) superclass.();
c) super.A();
d) super();

5. At line number 2 in the following code, choose 3 valid data-type attributes/qualifiers among “final,
static, native, public, private, abstract, protected”

public interface Status


{
/* insert qualifier here */ int MY_VALUE = 10;
}
a) final, native, private
b) final, static, protected
c) final, private, abstract
d) final, static, public

6. Which of these is supported by method overriding in Java?


a) Abstraction
b) Encapsulation
c) Polymorphism
d) None of the mentioned

7. What will be the output of the following Java program?

class Alligator
{
public static void main(String[] args)
{
int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
int [][]y = x;
[Link](y[2][1]);
}
}
a) 2
b) 3
c) 7
d) Compilation Error

8. What will be the output of the following Java program?

final class A
{
int i;
}
class B extends A
{
int j;
[Link](j + " " + i);
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
[Link]();
}
}
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error

9. What will be the output of the following Java program?

class Abc
{
public static void main(String[]args)
{
String[] elements = { "for", "tea", "too" };
String first = ([Link] > 0) ? elements[0]: null;
}
}
a) Compilation error
b) An exception is thrown at run time
c) The variable first is set to null
d) The variable first is set to elements[0]

10. What will be the output of the following Java program?

class A
{
int i;
public void display()
{
[Link](i);
}
}
class B extends A
{
int j;
public void display()
{
[Link](j);
}
}
class Dynamic_dispatch
{
public static void main(String args[])
{
B obj2 = new B();
obj2.i = 1;
obj2.j = 2;
A r;
r = obj2;
[Link]();
}
}
a) 1
b) 2
c) 3
d) 4

1. Which of these keywords are used to define an abstract class?


a) abst
b) abstract
c) Abstract
d) abstract class

2. Which of these is not abstract?


a) Thread
b) AbstractList
c) List
d) None of the Mentioned

3. If a class inheriting an abstract class does not define all of its function then it will be known as?
a) Abstract
b) A simple class
c) Static class
d) None of the mentioned

4. Which of these is not a correct statement?


a) Every class containing abstract method must be declared abstract
b) Abstract class defines only the structure of the class not its implementation
c) Abstract class can be initiated by new operator
d) Abstract class can be inherited

5. Which of these packages contains abstract keyword?


a) [Link]
b) [Link]
c) [Link]
d) [Link]

6. What will be the output of the following Java code?

class A
{
public int i;
private int j;
}
class B extends A
{
void display()
{
super.j = super.i + 1;
[Link](super.i + " " + super.j);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error

7. What will be the output of the following Java code?

class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
[Link](obj.i + " " + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error

8. What will be the output of the following Java code?

class A
{
int i;
void display()
{
[Link](i);
}
}
class B extends A
{
int j;
void display()
{
[Link](j);
}
}
class method_overriding
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
a) 0
b) 1
c) 2
d) Compilation Error

9. What will be the output of the following Java code?

class A
{
public int i;
protected int j;
}
class B extends A
{
int j;
void display()
{
super.j = 3;
[Link](i + " " + j);
}
}
class Output
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
a) 1 2
b) 2 1
c) 1 3
d) 3 1

1. Which of this keyword must be used to inherit a class?


a) super
b) this
c) extent
d) extends

2. A class member declared protected becomes a member of subclass of which type?


a) public member
b) private member
c) protected member
d) static member

3. Which of these is correct way of inheriting class A by class B?


a) class B + class A {}
b) class B inherits class A {}
c) class B extends A {}
d) class B extends class A {}

4. Which two classes use the Shape class correctly?

A. public class Circle implements Shape


{
private int radius;
}
B. public abstract class Circle extends Shape
{
private int radius;
}
C. public class Circle extends Shape
{
private int radius;
public void draw();
}
D. public abstract class Circle implements Shape
{
private int radius;
public void draw();
}
E. public class Circle extends Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
F. public abstract class Circle implements Shape
{
private int radius;
public void draw()
{
/* code here */
}
}
a) B,E
b) A,C
c) C,E
d) T,H

5. What will be the output of the following Java program?

class A
{
int i;
void display()
{
[Link](i);
}
}
class B extends A
{
int j;
void display()
{
[Link](j);
}
}
class inheritance_demo
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
a) 0
b) 1
c) 2
d) Compilation Error

6. What will be the output of the following Java program?

class A
{
int i;
}
class B extends A
{
int j;
void display()
{
super.i = j + 1;
[Link](j + " " + i);
}
}
class inheritance
{
public static void main(String args[])
{
B obj = new B();
obj.i=1;
obj.j=2;
[Link]();
}
}
a) 2 2
b) 3 3
c) 2 3
d) 3 2

7. What will be the output of the following Java program?

class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
[Link](obj.i + " " + obj.j)
}
}
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error

1. What is not type of inheritance?


a) Single inheritance
b) Double inheritance
c) Hierarchical inheritance
d) Multiple inheritance

2. Using which of the following, multiple inheritance in Java can be implemented?


a) Interfaces
b) Multithreading
c) Protected methods
d) Private methods

3. All classes in Java are inherited from which class?


a) [Link]
b) [Link]
c) [Link]
d) [Link]

4. In order to restrict a variable of a class from inheriting to subclass, how variable should be
declared?
a) Protected
b) Private
c) Public
d) Static

5. If super class and subclass have same variable name, which keyword should be used to use super
class?
a) super
b) this
c) upper
d) classname

6. Static members are not inherited to subclass.


a) True
b) False

7. Which of the following is used for implementing inheritance through an interface?


a) inherited
b) using
c) extends
d) implements

8. Which of the following is used for implementing inheritance through class?


a) inherited
b) using
c) extends
d) implements

9. What would be the result if a class extends two interfaces and both have a method with same
name and signature? Lets assume that the class is not implementing that method.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully

10. Does Java support multiple level inheritance?


a) True
b) False

1. Which of these class is superclass of String and StringBuffer class?


a) [Link]
b) [Link]
c) ArrayList
d) None of the mentioned
2. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

3. Which of this method of class String is used to obtain a length of String object?
a) get()
b) Sizeof()
c) lengthof()
d) length()

4. Which of these method of class String is used to extract a single character from a String object?
a) CHARAT()
b) chatat()
c) charAt()
d) ChatAt()

5. Which of these constructors is used to create an empty String object?


a) String()
b) String(void)
c) String(0)
d) None of the mentioned

6. Which of these is an incorrect statement?


a) String objects are immutable, they cannot be changed
b) String object can point to some other reference of String variable
c) StringBuffer class is used to store string in a buffer for later use
d) None of the mentioned

7. What will be the output of the following Java program?

class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
[Link](s);
}
}
a) a
b) b
c) c
d) abc

8. What will be the output of the following Java program?

class String_demo
{
public static void main(String args[])
{
int ascii[] = { 65, 66, 67, 68};
String s = new String(ascii, 1, 3);
[Link](s);
}
}
a) ABC
b) BCD
c) CDA
d) ABCD

9. What will be the output of the following Java program?

class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
String s1 = "abcd";
int len1 = [Link]();
int len2 = [Link]();
[Link](len1 + " " + len2);
}
}
a) 3 0
b) 0 3
c) 3 4
d) 4 3

1. When does Exceptions in Java arises in code sequence?


a) Run Time
b) Compilation Time
c) Can Occur Any Time
d) None of the mentioned

2. Which of these keywords is not a part of exception handling?


a) try
b) finally
c) thrown
d) catch

3. Which of these keywords must be used to monitor for exceptions?


a) try
b) finally
c) throw
d) catch
4. Which of these keywords must be used to handle the exception thrown by try block in some
rational manner?
a) try
b) finally
c) throw
d) catch

5. Which of these keywords is used to manually throw an exception?


a) try
b) finally
c) throw
d) catch

6. What will be the output of the following Java program?

class exception_handling
{
public static void main(String args[])
{
try
{
[Link]("Hello" + " " + 1 / 0);
}
catch(ArithmeticException e)
{
[Link]("World");
}
}
}
a) Hello
b) World
c) HelloWorld
d) Hello World

7. What will be the output of the following Java program?

class exception_handling
{
public static void main(String args[])
{
try
{
int a, b;
b = 0;
a = 5 / b;
[Link]("A");
}
catch(ArithmeticException e)
{
[Link]("B");
}
}
}
a) A
b) B
c) Compilation Error
d) Runtime Error

8. What will be the output of the following Java program?

class exception_handling
{
public static void main(String args[])
{
try
{
int a, b;
b = 0;
a = 5 / b;
[Link]("A");
}
catch(ArithmeticException e)
{
[Link]("B");
}
finally
{
[Link]("C");
}
}
}
a) A
b) B
c) AC
d) BC

9. What will be the output of the following Java program?

class exception_handling
{
public static void main(String args[])
{
try
{
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
sum = (sum / i);
}
catch(ArithmeticException e)
{
[Link]("0");
}
[Link](sum);
}
}
a) 0
b) 05
c) Compilation Error
d) Runtime Error

10. Which of these is a super class of all exceptional type classes?


a) String
b) RuntimeExceptions
c) Throwable
d) Cacheable

11. Which of these class is related to all the exceptions that can be caught by using catch?
a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned

12. Which of these class is related to all the exceptions that cannot be caught?
a) Error
b) Exception
c) RuntimeExecption
d) All of the mentioned

13. Which of these handles the exception when no catch is used?


a) Default handler
b) finally
c) throw handler
d) Java run time system

14. What exception thrown by parseInt() method?


a) ArithmeticException
b) ClassNotFoundException
c) NullPointerException
d) NumberFormatException

15. What will be the output of the following Java code?

class exception_handling
{
public static void main(String args[])
{
try
{
[Link]("Hello" + " " + 1 / 0);
}
finally
{
[Link]("World");
}
}
}
a) Hello
b) World
c) Compilation Error
d) First Exception then World

16. What will be the output of the following Java code?

class exception_handling
{
public static void main(String args[])
{
try
{
int i, sum;
sum = 10;
for (i = -1; i < 3 ;++i)
{
sum = (sum / i);
[Link](i);
}
}
catch(ArithmeticException e)
{
[Link]("0");
}
}
}
a) -1
b) 0
c) -10
d) -101

Applet

1. Which of these functions is called to display the output of an applet?


a) display()
b) paint()
c) displayApplet()
d) PrintApplet()

2. Which of these methods can be used to output a string in an applet?


a) display()
b) print()
c) drawString()
d) transient()
3. Which of these methods is a part of Abstract Window Toolkit (AWT) ?
a) display()
b) paint()
c) drawString()
d) transient()

4. Which of these modifiers can be used for a variable so that it can be accessed from any thread or
parts of a program?
a) transient
b) volatile
c) global
d) No modifier is needed

5. Which of these operators can be used to get run time information about an object?
a) getInfo
b) Info
c) instanceof
d) getinfoof

6. What is the Message is displayed in the applet made by the following Java program?

import [Link].*;
import [Link].*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
[Link]("A Simple Applet", 20, 20);
}
}
a) A Simple Applet
b) A Simple Applet 20 20
c) Compilation Error
d) Runtime Error

7. What is the length of the application box made by the following Java program?

import [Link].*;
import [Link].*;
public class myapplet extends Applet
{
public void paint(Graphics g)
{
[Link]("A Simple Applet", 20, 20);
}
}
a) 20
b) 50
c) 100
d) System dependent
8. What is the length of the application box made the following Java program?

import [Link].*;
import [Link].*;
public class myapplet extends Applet
{
Graphic g;
[Link]("A Simple Applet", 20, 20);
}
a) 20
b) Default value
c) Compilation Error
d) Runtime Error

Event Handling/AWT
1. Which of these packages contains all the classes and methods required for even handling in Java?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
View Answer

2. What is an event in delegation event model used by Java programming language?


a) An event is an object that describes a state change in a source
b) An event is an object that describes a state change in processing
c) An event is an object that describes any change by the user and system
d) An event is a class used for defining object, to create events
View Answer

3. Which of these methods are used to register a keyboard event listener?


a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()
View Answer

4. Which of these methods are used to register a mouse motion listener?


a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()
View Answer

5. What is a listener in context to event handling?


a) A listener is a variable that is notified when an event occurs
b) A listener is a object that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d) None of the mentioned
View Answer

6. Event class is defined in which of these libraries?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
View Answer

7. Which of these methods can be used to determine the type of event?


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()
View Answer

8. Which of these class is super class of all the events?


a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent
View Answer

9. Which of these events will be notified if scroll bar is manipulated?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent
View Answer

10. Which of these events will be generated if we close an applet’s window?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

11) Where are the following four methods commonly used?

1) public void add(Component c)


2) public void setSize(int width,int height)
3) public void setLayout(LayoutManager m)
4) public void setVisible(boolean)

a. Graphics class
b. Component class
c. Both A & B
d. None of the above

12) Give the abbreviation of AWT?

a. Applet Windowing Toolkit


b. Abstract Windowing Toolkit
c. Absolute Windowing Toolkit
d. None of the above
13) In Graphics class which method is used to draws a rectangle with the specified width and
height?

a. public void drawRect(int x, int y, int width, int height)


b. public abstract void fillRect(int x, int y, int width, int height)
c. public abstract void drawLine(int x1, int y1, int x2, int y2)
d. public abstract void drawOval(int x, int y, int width, int height)

14) Which method can set or change the text in a Label?

a. setText()
b. getText()
c. All the above
d. None of the above

15) Which is a component in AWT that can contain another components like buttons, textfields,
labels etc.?

a. Window
b. Container
c. Panel
d. Frame

16) How many types of controls does AWT support?

a. 7
b. 6
c. 5
d. 8

17) The following


a) It is lightweight.
b) It supports pluggable look and feel.
c) It follows MVC (Model View Controller) architecture
are the advantages of _____ .

a. Swing
b. AWT
c. Both A & B
d. None of the above

18) AWT is used for GUI programming in java

a. True
b. False
Answer Explanation

19) The ActionListener interface is not used for handling action events
a. True
b. False

JDBC

1. Which of the following contains both date and time?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
View Answer

2. Which of the following is advantage of using JDBC connection pool?


a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance
View Answer

3. Which of the following is advantage of using PreparedStatement in Java?


a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage
View Answer

4. Which one of the following contains date information?


a) [Link]
b) [Link]
c) [Link]
d) [Link]
View Answer

5. What does setAutoCommit(false) do?


a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction
View Answer

6. Which of the following is used to call stored procedure?


a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement
View Answer

7. Which of the following is used to limit the number of rows returned?


a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)
View Answer

8. Which of the following is method of JDBC batch process?


a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()
View Answer

9. Which of the following is used to rollback a JDBC transaction?


a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()
View Answer

Q 1 - Which of the following is correct about Connection interface of JDBC?

A - Connection interface consists of methods for contacting a database.

B - It represents communication context.

C - Both of the above.

D - none of the above.

Q 2 - In which of the following type of ResultSet, the cursor can scroll forwards and backwards, and
the result set is not sensitive to changes made by others to the database that occur after the result
set was created.?

A - ResultSet.TYPE_FORWARD_ONLY

B - ResultSet.TYPE_SCROLL_INSENSITIVE

C - ResultSet.TYPE_SCROLL_SENSITIVE

D - None of the above.

Q 3 - Which of the following type of JDBC driver, talks with the server-side middleware that then
talks to database?

A - JDBC-ODBC Bridge plus ODBC driver

B - Native-API, partly Java driver

C - JDBC-Net, pure Java driver

D - Native-protocol, pure Java driver


Q 4 - Which of the following type of JDBC driver is typically used for development and testing
purposes only?

A - Type 1

B - Type 2

C - Type 3

D - Type 4

Q 5 - Which of the following is efficient than statement due to pre-compilation of SQL?

A - Statement

B - PreparedStatement

C - CallableStatement

D - None of the above.

Q 6 - Which of the following is used generally used for altering the databases?

A - boolean execute()

B - ResultSet executeQuery()

C - int executeUpdate()

D - None of the above.

Q 7 - Which of the following is correct about connection pooling?

A - Database vendor's help multiple clients to share a cached set of connection objects that provides
access to a database.

B - Clients need not create a new connection everytime to interact with the database.

C - Both of the above.

D - None of the above.

Q 8 - Which of the following is correct about CallableStatement?

A - Used when you want to access the database stored procedures.

B - The CallableStatement interface can accept runtime input parameters.

C - Both of the above.

D - None of the above.


Q 9 - What is the use of blob, clob datatypes in JDBC?

A - These are used to store large amount of data into database like images, movie etc which are
extremely large in size.

B - These are used to store XML data.

C - Both of the above.

D - None of the above.

Packages:
1. Which of these keywords is used to define packages in Java?
a) pkg
b) Pkg
c) package
d) Package

2. Which of these is a mechanism for naming and visibility control of a class and its content?
a) Object
b) Packages
c) Interfaces
d) None of the Mentioned.

3. Which of this access specifies can be used for a class so that its members can be accessed by a
different class in the same package?
a) Public
b) Protected
c) No Modifier
d) All of the mentioned

4. Which of these access specifiers can be used for a class so that its members can be accessed by a
different class in the different package?
a) Public
b) Protected
c) Private
d) No Modifier

5. Which of the following is the correct way of importing an entire package ‘pkg’?
a) import pkg.
b) Import pkg.
c) import pkg.*
d) Import pkg.*

6. Which of the following is an incorrect statement about packages?


a) Package defines a namespace in which classes are stored
b) A package can contain other package within it
c) Java uses file system directories to store packages
d) A package can be renamed without renaming the directory in which the classes are stored

7. Which of the following package stores all the standard java classes?
a) lang
b) java
c) util
d) [Link]

8. What will be the output of the following Java program?

package pkg;
class display
{
int x;
void show()
{
if (x > 1)
[Link](x + " ");
}
}
class packages
{
public static void main(String args[])
{
display[] arr=new display[3];
for(int i=0;i<3;i++)
arr[i]=new display();
arr[0].x = 0;
arr[1].x = 1;
arr[2].x = 2;
for (int i = 0; i < 3; ++i)
arr[i].show();
}
}
Note : [Link] file is in directory pkg;
a) 0
b) 1
c) 2
d) 0 1 2

9. What will be the output of the following Java program?

package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello");
[Link](1, ‘x’);
[Link](s1);
}
}
a) xello
b) xxxxx
c) Hxllo
d) Hexlo

10. What will be the output of the following Java program?

package pkg;
class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Hello World");
[Link](6 , "Good ");
[Link](s1);
}
}
Note : [Link] file is not in directory pkg.
a) HelloGoodWorld
b) HellGoodoWorld
c) Compilation error
d) Runtime error

You might also like