Question 1:
What is the output of this program?
1. class ArrayOutput {
2. public static void main(String args[])
3. {
4. char array_variable [] = new char[10];
5. for (int i = 0; i < 10; ++i) {
6. array_variable[i] = 'i';
7. System.out.print(array_variable[i] + "" );
8. i++;
9. }
10. }
11. }
a) iiiii
b) 01234
c) ijklm
d) None of the mentioned
2. What is the output of this program?
1. class AsciiCodes {
2. public static void main(String args[])
3. {
4. char var1 = 'A';
5. char var2 = 'a';
6. System.out.println((int)var1 + " " + (int)var2);
7. }
8. }
a) 162
b) 65 97
c) 67 95
d) 66 98
3. What is the range of data type short in Java?
a) -216 to 216
b) -216-1 to 216-1
c) -216-1 to 216-1 - 1
d) None of the mentioned
4. Which of these data types is used to store command line arguments?
a) Array
b) Stack
c) String
d) Integer
5. What is the output of this program, Command line execution is done as – java
Output “This is a command Line”?
1. class Output {
2. public static void main(String args[]) {
3. System.out.print("args");
4. }
5. }
a) Compilation Error
b) java Output This is a command Line
c) This is a command Line
d) None of the above
6. What is the output of this program, Command line execution is done as – java
Output command Line 10 A b 4 N?
1. class Output {
2. public static void main(String args[]) {
3. System.out.print(args[6]);
4. }
5. }
a) java
b) 10
c) b
d) N
7. What is the use of try & catch?
a) It allows us to manually handle the exception.
b) It allows to fix errors.
c) It prevents automatic terminating of the program in cases when an exception
occurs.
d) All of the mentioned.
8. What is the output of this program?
1. class Output {
2. public static void main(String args[]) {
3. try {
4. int a = 0;
5. int b = 5;
6. int c = b / a;
7. System.out.print("Hello");
8. }
9. catch(Exception e) {
10. System.out.print("World");
11. }
12. }
13. }
a) Hello
b) World
c) HelloWOrld
d) Compilation Error
9.The Following steps are required to perform 1) Implement the Listener interface
and overrides its methods 2) Register the component with the Listener
a) Exception Handling
b) String Handling
c) Event Handling
d) None of the above
10. What is the output of this program?
1. class Output {
2. public static void main(String args[]) {
3. try {
4. int a = 0;
5. int b = 5;
6. int c = b / a;
7. System.out.print("Hello");
8. }
9. catch(Exception e) {
10. System.out.print("World");
11. }
12. finally {
13. System.out.print("World");
14. }
15. }
16. }
a) WorldWorld
b) World
c) HelloWOrld
d) Hello
11. 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
12. What is the output of this program?
1. class A {
2. public int i;
3. private int j;
4. }
5. class B extends A {
6. void display() {
7. super.j = super.i + 1;
8. System.out.println(super.i + " " + super.j);
9. }
10. }
11. class inheritance {
12. public static void main(String args[])
13. {
14. B obj = new B();
15. obj.i=1;
16. obj.j=2;
17. obj.display();
18. }
19. }
a) 2 2
b) 3 3
c) Compilation Error
d) Runtime Error
13. How do we inherit existing interface to a new interface? We use ___ keyword.
a) extend
b) implements
c) extends
d) implement
14. Which of these methods deletes all the elements from invoking collection?
a) clear()
b) reset()
c) delete()
d) refresh()
15. Which of these packages contains all the classes and methods required for even
handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event
16. What is the value returned by function compareTo() if the invoking string is less
than the string compared?
a) zero
b) value less than zero
c) value greater than zero
d) None of the mentioned
17. What is the output of this program?
1. class output {
2. public static void main(String args[])
3. {
4. String s1 = "Hello i love java";
5. String s2 = new String(s1);
6. System.out.println((s1 == s2) + " " + s1.equals(s2));
7. }
8. }
a) true true
b) false false
c) true false
d) false true
18. What will be the output of the program?
String a = "ABCD";
String b = a.toLowerCase();
b = b.replace('a','d');
b = b.replace('b','c');
System.out.println(b);
a) abcd
b) ABCD
c) dccd
d) dcba
19. Which of these keywords is used to refer to member of base class from a sub
class?
a) upper
b) super
c) this
d) None of the mentioned
20. A class member declared protected becomes member of subclass of which
type?
a) public member
b) private member
c) protected member
d) static member
21. Which of these is supported by method overriding in Java?
a) Abstraction
b) Encapsulation
c) Polymorphism
d) None of the mentioned
22. What is the output of this program?
1. class A {
2. int i;
3. int j;
4. A() {
5. i = 1;
6. j = 2;
7. }
8. }
9. class Output {
10. public static void main(String args[])
11. {
12. A obj1 = new A();
13. System.out.print(obj1.toString());
14. }
15. }
a) String associated with obj1
b) false
c) true
d) Compilation Error
23. Which of these access specifiers must be used for main() method?
a) private
b) public
c) protected
d) None of the mentioned
24. 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.
25. 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
26. If an expression contains double, int, float, long, then whole expression will
promoted into which of these data types?
a) long
b) int
c) double
d) float
27. What is the output of this program?
1. class bitwise_operator {
2. public static void main(String args[])
3. {
4. int var1 = 42;
5. int var2 = ~var1;
6. System.out.print(var1 + " " + var2);
7. }
8. }
a) 42 -42
b) 43 -43
c) 42 43
d) 42 -43
28. What is the output of this program?
1. class Output {
2. public static void main(String args[])
3. {
4. int a = 1;
5. int b = 2;
6. int c = 3;
7. a |= 4;
8. b >>= 1;
9. c <<= 1;
10. a ^= c;
11. System.out.println(a + " " + b + " " + c);
12. }
13. }
a) 3 1 6
b) 2 2 3
c) 2 3 4
d) 3 3 6
29. Which of these selection statements test only for equality?
a) if
b) switch
c) if & switch
d) None of the mentioned
30. 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
31. Consider the following code snippet:
int i=10;
while(i==10)
{
System.out.printf("Welcome to java");
i--;
}
How many times the loop will iterate and print “Welcome to Java”. Enter numeric
value only in the box below.
32. What is the output of the following program?
class RightShiftOperator {
public static void main (String args [])
{
int x;
x = 10;
x = x >>> 1;
System.out.println(x);
}
}
a) 10
b) 2
c) 5
d) 20
33. OOP features are
i) Increasing productivity ii) Reusability
iii) Decreasing maintenance cost iv) High vulnerability
a) 1,2 & 4
b) 1,2 & 3
c) 1, 2 & 4
d) none of the above
34. Which of these methods can be used to convert all characters in a String into a
character array?
a) charAt()
b) getChars()
c) toCharArray()
d) b and c
35. The following program is an example for?
class Student{
int id;
String name;
void display() { System.out.println(“” + id + " " + name); }
public static void main(String args[]){
Student s1=new Student();
Student s2=new Student();
s1.display();
s2.display();
}
}
a. Parameterized constructor
b. Default Constructor
c. Overloading Constructor
d. None of the above
36. Which of the tool is used to compile java code?
a) jar
b) javac
c) javadoc
d) java
37. Which of the following is not a keyword in java?
a) static
b) Boolean
c) void
d) private
38. What of the following is the default value of a local variable?
a) null
b) 0
c) Depends upon the type of variable
d) Not assigned
39. What kind of variables a class can consist of?
a) class variables, instance variables
b) class variables, local variables, instance variables
c) class variables
d) class variables, local variables
40. Which of the following is Faster, StringBuilder or StringBuffer?
a) StringBuilder
b) StringBuffer
c) Both of the above.
d) none of the above.