Objective Questions-Java
Objective Questions-Java
a) Dynamic
b) Architecture Neutral
c) Use of pointers
d) Object-oriented
3. What should be the execution order, if a class has a method, static block, instance block,
and constructor, as shown below?
public class First_C {
public void myMethod()
{ System.out.println("Method"); }
{ System.out.println(" Instance Block"); }
public void First_C() { System.out.println("Constructor "); }
static { System.out.println("static block"); }
public static void main(String[] args) {
First_C c = new First_C();
c.First_C();
c.myMethod();
}
}
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
8. What is not the use of “this” keyword in Java?
a) Referring to the instance variable when a local variable has the same name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining
9. 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
10. What is the extension of compiled java classes?
a) .txt
b) .js
c) .class
d) .java
11. Which exception is thrown when java is out of memory?
a) MemoryError
b) OutOfMemoryError
c) MemoryOutOfBoundsException
d) MemoryFullException
12. 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;
System.out.println(y[2][1]);
}
}
a) Compilation Error
b) 2
c) 3
d) 7
13. Which of these are selection statements in Java?
a) break
b) continue
c) for()
d) if()
14. Which of these keywords is used to define interfaces in Java?
a) intf
b) Intf
c) interface
d) Interface
15. Which of these class is a superclass of every class in Java?
a) ArrayList class
b) Abstract class
c) Object class
d) String class
16. Which of these keywords can be used to prevent Method overriding in Java?
a) final
b) protected
c) static
d) constant
17. Which of these keywords are used for the block to be examined for exceptions?
a) check
b) throw
c) catch
d) try
18. Which one of the following is not an access modifier?
a) Protected
b) Void
c) Public
d) Private