Name
Date
JAVA & OOP Quiz Score
1. Which statement is t ue about Java?
A Java is a sequence-dependent programming language
B Java is a code dependent programming language
C Java is a platfo m-dependent programming language
D Java is a platfo m-independent programming language
2. Which component is used to compile, debug and execute the java programs?
A JRE
B JIT
C JDK
D JVM
3. Which one of the following is not a Java feature?
A Object-o iented
B Use of pointers
C Po table
D Dynamic and Extensible
4. Which of these cannot be used for a va iable name in Java?
A Identifiers & Keyword
B None of the mentioned
C Identifiers
D Keyword
5. What is the extension of java code files?
A .js
B .txt
C .class
D .java
6. What will be the output of the following Java code?
class increment {
public static void main(St ing args[])
{
int g = 3;
System.out.p int(++g * 8 ;
}
}
A 32
B 33
C 24
D 25
7. What will be the output of the following Java program?
class output {
public static void main(St ing args[])
{
double a, b,c;
a = 3.0/0;
b = 0/4.0;
c=0/0.0;
System.out.p intln(a);
System.out.p intln(b);
System.out.p intln(c);
}
}
A NaN
B Infinity
C 0.0
D All of the mentioned
8. Which of the following is not an OOPS concept in Java?
A Polymorphism
B Compilation
C Inhe itance
D Encapsulation
9. What is not the use of “this” keyword in Java?
A Passing itself to the method of the same class
B Refe ing to the instance va iable when a local va iable has the same name
C Passing itself to another method
D Calling another const uctor in const uctor chaining
10. What will be the output of the following Java program?
class va iable_scope
{
public static void main(St ing args[])
{
int x;
x = 5;
{
int y = 6;
System.out.p int(x + " " + y);
}
System.out.p intln(x + " " + y);
}
}
A Compilation e ror
B Runtime e ror
C 5656
D 565
11. What will be the e ror in the following Java code?
byte b = 50;
b = b * 50;
A b cannot contain value 50
B b cannot contain value 100, limited by its range
C No e ror in this code
D * operator has conve ted b * 50 into int, which can not be conve ted to byte without casting
12. Which of the following is a type of polymorphism in Java Programming?
A Multiple polymorphism
B Compile time polymorphism
C Multilevel polymorphism
D Execution time polymorphism
13. What will be the output of the following Java program?
class leftshift_operator
{
public static void main(St ing args[])
{
byte x = 64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2
System.out.p int(i + " " + y);
}
}
A 0 256
B 0 64
C 256 0
D 64 0
14. What will be the output of the following Java code?
class box
{
int width;
int height;
int length;
}
class main
{
public static void main(St ing args[])
{
box obj = new box();
obj.width = 10;
obj.height = 2;
obj.length = 10;
int y = obj.width * obj.height * obj.length;
System.out.p int(y);
}
}
A 100
B 400
C 200
D 12
15. What is T uncation in Java?
A Floating-point value assigned to a Floating type
B Floating-point value assigned to an integer type
C Integer value assigned to floating type
D Integer value assigned to floating type
16. What will be the output of the following Java program?
class Output
{
public static void main(St ing args[])
{
int a r[] = 1, 2, 3, 4, 5 ;
for ( int i = 0; i < a r.length - 2; ++i)
System.out.p intln(a r[i] + " ");
}
}
A 12345
B 1234
C 12
D 123
17. What will be the output of the following Java code snippet?
class abc
{
public static void main(St ing args[])
{
if(args.length>0
System.out.p intln(args.length);
}
}
A The snippet compiles and uns but does not p int anything
B The snippet compiles, uns and p ints 0
C The snippet compiles, uns and p ints 1
D The snippet does not compile
18. What is the extension of compiled java classes?
A .txt
B .js
C .java
D .class
19. Which exception is thrown when java is out of memo y?
A Memo yE ror
B OutOfMemo yE ror
C Memo yOutOfBoundsException
D Memo yFullException
20. What will be the output of the following Java code?
class St ing_demo
{
public static void main(St ing args[])
{
char chars[] = {'a', 'b', 'c'};
St ing s = new St ing(chars);
System.out.p intln(s);
}
}
A abc
B a
C b
D c
21. Which of these are selection statements in Java?
A break
B continue
C for()
D None of the mentioned
22. What will be the output of the following Java program?
class recursion
{
int func (int n)
{
int result;
if (n == 1
retu n 1;
result = func (n - 1 ;
retu n result;
}
}
class Output
{
public static void main(St ing args[])
{
recursion obj = new recursion() ;
System.out.p int(obj.func(5 ;
}
}
A 1
B 120
C 0
D None of the mentioned
23. What will be the output of the following Java code?
class output
{
public static void main(St ing args[])
{
St ing c = "Hello i love java";
boolean var;
var = c.sta tsWith("hello");
System.out.p intln(var);
}
}
A 0
B t ue
C 1
D false
24. What will be the output of the following Java program?
class output
{
public static void main(St ing args[])
{
St ingBuffer s1 = new St ingBuffer("Quiz");
St ingBuffer s2 = s1.reverse();
System.out.p intln(s2 ;
}
}
A QuizziuQ
B ziuQQuiz
C Quiz
D ziuQ
25. What will be the output of the following Java code?
class Output
{
public static void main(St ing args[])
{
Integer i = new Integer(257 ;
byte x = i.byteValue();
System.out.p int(x);
}
}
A 257
B 256
C 1
D 0
26. What will be the output of the following Java program?
class Output
{
public static void main(St ing args[])
{
double x = 2.0;
double y = 3.0;
double z = Math.pow( x, y );
System.out.p int(z);
}
}
A 9.0
B 8.0
C 4.0
D 2.0
27. Which of the following is a superclass of eve y class in Java?
A A rayList
B Abstract Class
C Object Class
D St ing
28. What will be the output of the following Java code?
class Output
{
public static void main(St ing args[])
{
double x = 3.14;
int y = (int) Math.ceil(x);
System.out.p int(y);
}
}
A 3
B 0
C 4
D 3.0
29. What will be the output of the following Java code snippet?
impo t java.util.*;
class A raylists
{
public static void main(St ing args[])
{
A rayLists obj = new A rayLists();
obj.add("A");
obj.add("B");
obj.add("C");
obj.add(1, "D");
System.out.p intln(obj);
}
}
A A, D, C
B A, B, C
C A, B, C, D
D A, D, B, C
30. What will be the output of the following Java program?
impo t java.util.*;
class Collection_iterators
{
public static void main(St ing args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2 ;
list.add(new Integer(8 ;
list.add(new Integer(5 ;
list.add(new Integer(1 ;
Iterator i = list.iterator();
Collections.reverse(list);
Collections.so t(list);
while(i.hasNext())
System.out.p int(i.next() + " ");
}
}
A 1258
B 2185
C 1582
D 2851