Oops QB
Oops QB
1.if(a<=0)
2.{
3. if(a==0)
4. {
5. System.out.println("1 ");
6. }
7. else
8. {
9. System.out.println("2 ");
10. }
11. }
12. System.out.println("3 ");
a) 1 2
b) 2 3
c) 1 3
d) 3
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
switch(a)
{
System.out.println("Hello World");
}
a) int and float
b) byte and short
c) char and long
d) byte and char
9. Which of these are selection statements in Java?
a) if()
b) for()
c) continue
d) break
10. What will be the output of the following Java program?
1. class selection_statements
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. if ((var2 = 1) == var1)
8. System.out.print(var2);
9. else
10. System.out.print(++var2);
11. }
12. }
a) 1
b) 2
c) 3
d) 4
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
1. class comma_operator
2. {
3. public static void main(String args[])
4. {
5. int sum = 0;
6. for (int i = 0, j = 0; i < 5 & j < 5; ++i, j =
i + 1)
7. sum += i;
8. System.out.println(sum);
9. }
10. }
a) 5
b) 6
c) 14
d) compilation error
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int a = 5;
6. int b = 10;
7. first:
8. {
9. second:
10. {
11. third:
12. {
13. if (a == b >> 1)
14. break second;
15. }
16. System.out.println(a);
17. }
18. System.out.println(b);
19. }
20. }
21. }
a) 5 10
b) 10 5
c) 5
d) 10
line?
1. &
2. ^
3. ?:
a) 1 -> 2 -> 3
b) 2 -> 1 -> 3
c) 3 -> 2 -> 1
d) 2 -> 3 -> 1
1. class operators
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. int var3;
8. var3 = ++ var2 * var1 / var2 + var2;
9. System.out.print(var3);
10. }
11. }
a) 10
b) 11
c) 12
d) 56
1. class operators
2. {
3. public static void main(String args[])
4. {
5. int x = 8;
6. System.out.println(++x * 3 + " " + x);
7. }
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
8. }
a) 24 8
b) 24 9
c) 27 8
d) 27 9
17. Which of these operators can skip evaluating right hand operand?
a) !
b) |
c) &
d) &&
18. 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
19. What will be the output of the following Java code?
1. class Relational_operator
2. {
3. public static void main(String args[])
4. {
5. int var1 = 5;
6. int var2 = 6;
7. System.out.print(var1 > var2);
8. }
9. }
a) 1
b) 0
c) true
d) false
1. class bool_operator
2. {
3. public static void main(String args[])
4. {
5. boolean a = true;
6. boolean b = !true;
7. boolean c = a | b;
8. boolean d = a & b;
9. boolean e = d ? b : c;
10. System.out.println(d + " " + e);
11. }
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
12. }
a) false false
b) true ture
c) true false
d) false true
1. class ternary_operator
2. {
3. public static void main(String args[])
4. {
5. int x = 3;
6. int y = ~ x;
7. int z;
8. z = x > y ? x : y;
9. System.out.print(z);
10. }
11. }
a) 0
b) 1
c) 3
d) -4
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int x , y = 1;
6. x = 10;
7. if (x != 10 && x / 0 == 0)
8. System.out.println(y);
9. else
10. System.out.println(++y);
11. }
12. }
a) 1
b) 2
c) Runtime error owing to division by zero in if condition
d) Unpredictable behavior of program
1. class Output
2. {
3. public static void main(String args[])
4. {
5. boolean a = true;
6. boolean b = false;
7. boolean c = a ^ b;
8. System.out.println(!c);
9. }
10. }
a) 0
b) 1
c) false
d) true
24. Which operator is used to invert all the digits in a binary representation of a
number?
a) ~
b) <<<
c) >>>
d) ^
25. Which right shift operator preserves the sign of the value?
a) <<
b) >>
c) <<=
d) >>=
26. Which of these statements are incorrect?
a) The left shift operator, <<, shifts all of the bits in a value to the left
specified number of times
b) The right shift operator, >>, shifts all of the bits 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
27. What will be the output of the following Java program?
1. class bitwise_operator
2. {
3. public static void main(String args[])
4. {
5. int var1 = 42;
6. int var2 = ~var1;
7. System.out.print(var1 + " " + var2);
8. }
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
9. }
a) 42 42
b) 43 43
c) 42 -43
d) 42 43
1. class bitwise_operator
2. {
3. public static void main(String args[])
4. {
5. int a = 3;
6. int b = 6;
7. int c = a | b;
8. int d = a & b;
9. System.out.println(c + " " + d);
10. }
11. }
a) 7 2
b) 7 7
c) 7 5
d) 5 2
1. class Output
2. {
3. public static void main(String args[])
4. {
5. int a = 1;
6. int b = 2;
7. int c = 3;
8. a |= 4;
9. b >>= 1;
10. c <<= 1;
11. a ^= c;
12. System.out.println(a + " " + b + " " +
c);
13. }
14. }
a) 3 1 6
b) 2 2 3
c) 2 3 4
d) 3 3 6
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
30. 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
1. class main_class
2. {
3. public static void main(String args[])
4. {
5. int x = 9;
6. if (x == 9)
7. {
8. int x = 8;
9. System.out.println(x);
10. }
11. }
12. }
a) 9
b) 8
c) Compilation error
d) Runtime error
1. class box
2. {
3. int width;
4. int height;
5. int length;
6. }
7. class mainclass
8. {
9. public static void main(String args[])
10. {
11. box obj = new box();
12. obj.width = 10;
13. obj.height = 2;
14. obj.length = 10;
15. int y = obj.width * obj.height *
obj.length;
16. System.out.print(y);
17. }
18. }
a) 12
b) 200
c) 400
d) 100
1. class box
2. {
3. int width;
4. int height;
5. int length;
6. }
7. class mainclass
8. {
9. public static void main(String args[])
10. {
11. box obj1 = new box();
12. box obj2 = new box();
13. obj1.height = 1;
14. obj1.length = 2;
15. obj1.width = 1;
16. obj2 = obj1;
17. System.out.println(obj2.height);
18. }
19. }
a) 1
b) 2
c) Runtime error
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
d) Garbage value
37. Which component is used to compile, debug and execute java program?
a) JVM
b) JDK
c) JIT
d) JRE
38. 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
39. What is the extension of java code files?
a) .class
b) .java
c) .txt
d) .js
40. 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
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
1. class Alligator
2. {
3. public static void main(String[] args)
4. {
5. int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};
6. int [][]y = x;
7. System.out.println(y[2][1]);
8. }
9. }
a) 2
b) 3
c) 7
d) Compilation Error
1. final class A
2. {
3. int i;
4. }
5. class B extends A
6. {
7. int j;
8. System.out.println(j + " " + i);
9. }
10. class inheritance
11. {
12. public static void main(String args[])
13. {
14. B obj = new B();
15. obj.display();
16. }
17. }
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
1. class Abc
2. {
3. public static void main(String[]args)
4. {
5. String[] elements = { "for", "tea", "too" };
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
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]
1. class recursion
2. {
3. int func (int n)
4. {
5. int result;
6. result = func (n - 1);
7. return result;
8. }
9. }
10. class Output
11. {
12. public static void main(String args[])
13. {
14. recursion obj = new recursion() ;
15. System.out.print(obj.func(12));
16. }
17. }
a) 0
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
b) 1
c) Compilation Error
What will be the output of the following Java program?
1. class recursion
2. {
3. int func (int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = func (n - 1);
9. return result;
10. }
11. }
12. class Output
13. {
14. public static void main(String args[])
15. {
16. recursion obj = new recursion() ;
17. System.out.print(obj.func(5));
18. }
19. }
a) 0
b) 1
c) 120
d) None of the mentioned
1. class recursion
2. {
3. int fact(int n)
4. {
5. int result;
6. if (n == 1)
7. return 1;
8. result = fact(n - 1) * n;
9. return result;
10. }
11. }
12. class Output
13. {
14. public static void main(String args[])
15. {
16. recursion obj = new recursion() ;
17. System.out.print(obj.fact(1));
18. }
19. }
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
a) 1
b) 30
c) 120
d) Runtime Error
15. What will be the output of the following Java snippet, if attempted to
compile and run this code with command line argument “java abc Rakesh
Sharma”?
16. What will be the output of the following Java snippet, if attempted to
compile and execute?
1.class abc
2.{
3. public static void main(String args[])
4. {
5. if(args.length>0)
6. System.out.println(args.length);
7. }
8.}
17. What will be the output of the following Java snippet, if compiled and
executed with command line argument “java abc 1 2 3”?
4. {
5. for(int n=1;n<xyz.length; n++)
6. {
7. System.out.println(xyz[n]+"");
8. }
9. }
10. }
a) 1 2
b) 2 3
c) 1 2 3
d) Compilation error
18. What will be the output of the following Java code snippet running with
“java demo I write java code”?
19. What will be the output of the following Java snippet, if compiled and
executed with command line “hello there”?
1. class A
2. {
3. public int i;
4. private int j;
5. }
6. class B extends A
7. {
8. void display()
9. {
10. super.j = super.i + 1;
11. System.out.println(super.i + " " +
super.j);
12. }
13. }
14. class inheritance
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
15. {
16. public static void main(String args[])
17. {
18. B obj = new B();
19. obj.i=1;
20. obj.j=2;
21. obj.display();
22. }
23. }
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
1. class A
2. {
3. public int i;
4. public int j;
5. A()
6. {
7. i = 1;
8. j = 2;
9. }
10. }
11. class B extends A
12. {
13. int a;
14. B()
15. {
16. super();
17. }
18. }
19. class super_use
20. {
21. public static void main(String args[])
22. {
23. B obj = new B();
24. System.out.println(obj.i + " " + obj.j)
25. }
26. }
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
1. class A
2. {
3. public int i;
4. protected int j;
5. }
6. class B extends A
7. {
8. int j;
9. void display()
10. {
11. super.j = 3;
12. System.out.println(i + " " + j);
13. }
14. }
15. class Output
16. {
17. public static void main(String args[])
18. {
19. B obj = new B();
20. obj.i=1;
21. obj.j=2;
22. obj.display();
23. }
24. }
a) 1 2
b) 2 1
c) 1 3
d) 3 1
a) inherited
b) using
c) extends
d) implements
32. 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
33. 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()
34. 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
35. What will be the output of the following Java program?
1. class String_demo
2. {
3. public static void main(String args[])
4. {
5. char chars[] = {'a', 'b', 'c'};
6. String s = new String(chars);
7. System.out.println(s);
8. }
9. }
a) a
b) b
c) c
d) abc
1. class String_demo
2. {
3. public static void main(String args[])
4. {
5. int ascii[] = { 65, 66, 67, 68};
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
a) ABC
b) BCD
c) CDA
d) ABCD
1. class String_demo
2. {
3. public static void main(String args[])
4. {
5. char chars[] = {'a', 'b', 'c'};
6. String s = new String(chars);
7. String s1 = "abcd";
8. int len1 = s1.length();
9. int len2 = s.length();
10. System.out.println(len1 + " " + len2);
11. }
12. }
a) 3 0
b) 0 3
c) 3 4
d) 4 3
StringBuffer s1 = "one";
StringBuffer s2 = s1.append("two")
a) one
b) two
c) onetwo
d) twoone
39. Which of this method of class StringBuffer is used to get the length of the
sequence of characters?
a) length()
b) capacity()
c) Length()
d) Capacity()
KCG COLLEGE OF TECHNOLOGY
DEPARTMENT OF CSE & IT
CS8392:OBJECT ORIENTED PROGRAMMING
1. class output
2. {
3. public static void main(String args[])
4. {
5. StringBuffer c = new StringBuffer("Hello");
6. System.out.println(c.length());
7. }
8. }
a) 4
b) 5
c) 6
d) 7