java exam 0 votes, 0 avg 1 123456789101112131415 Java Questions 1 / 15 1. What is the default value of String variable? A. “” B. '’ C. null D. not defined 2 / 15 2. What will be the output of the following Java program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } A. 1 B. 120 C. O D. None of the mentioned 3 / 15 3. 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 4 / 15 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 / 15 5. What is the function of javap command? A. This command is used to run java compiler B. A command to run a non-optimized version of the java compiler C. A command to create HTML document in API style D. A command to seperate java class files 6 / 15 6. 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(); } } A. Method, constructor, instance block, and static block B. Instance block, method, static block, and constructor C. Static block, method, instance block, and constructor D. Static block, instance block, constructor, and method 7 / 15 7. How to convert Date object to String? A. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.parse(new Date()); B. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); sdf.format(new Date()); C. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().parse(); D. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd"); new Date().format(); 8 / 15 8. What will be the output of the following Java code snippet? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } A. The snippet compiles and runs but does not print anything B. The snippet compiles, runs and prints 0 C. The snippet compiles, runs and prints 1 D. The snippet does not compile 9 / 15 9. What is true about final class? A. class declared final is a final class B. final classes are created so the methods implemented by that class cannot be overidden C. It can’t be inherited D. all of the above 10 / 15 10. 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; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } A. 1 2 B. 2 1 C. 1 3 D. 3 1 11 / 15 11. Which data type value is returned by all transcendental math functions? A. int B. float C. double D. long 12 / 15 12. Which of the following is true about public access modifier? A. Variables, methods and constructors which are declared public can be accessed by any class B. Variables, methods and constructors which are declared public can be accessed by any class lying in same pacckage. C. Variables, methods and constructors which are declared public in the superclass can be accessed only by it’s child class. D. none of the above 13 / 15 13. 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(); 14 / 15 14. Which of the following are not java modifiers? A. public B. private C. friendly D. transient 15 / 15 15. What is not the use of “this” keyword in Java? A. Passing itself to the method of the same class B. Referring to the instance variable when a local variable has the same name C. Passing itself to another method D. Calling another constructor in constructor chaining Your score is The average score is 27% LinkedIn Facebook Twitter VKontakte 0% Restart quiz