java exam 0 votes, 0 avg 196 123456789101112131415 Java Questions 1 / 15 1. 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 2 / 15 2. What will be the output of the following Java code? class output { public static void main(String args[]) { String chars[] = {"a", "b", "c", "a", "c"}; for (int i = 0; i < chars.length; ++i) for (int j = i + 1; j < chars.length; ++j) if(chars[i].compareTo(chars[j]) == 0) System.out.print(chars[j]); } } A. ab B. bc C. ca D. ac 3 / 15 3. Find the output of the following code. class box { int width; int height; int length; } class main { public static void main(String args[]) { box obj = new box(); obj.width = 10; obj.height = 2; obj.length = 10; int y = obj.width * obj.height * obj.length; System.out.print(y); } } A. 100 B. 400 C. 200 D. 12 4 / 15 4. What does Object Oriented Programming means? A. Writing a program composed of java classes B. Writing an algorithm before writing your program and having a test plan C. Being objective about what you develop D. Desigining the application based on the objects discovered when analysing the problem 5 / 15 5. What is garbage collection in the context of Java? A. The JVM checks the output of any Java program and deletes anything that doesn’t make sense B. Any package imported in a program and not used is automatically deleted. C. When all references to an object are gone the memory used by the object is not reclaimed. D. When all references to an object are gone, the memory used by the object is automatically reclaimed. 6 / 15 6. 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 7 / 15 7. 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 8 / 15 8. What will be the output of the following Java program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } A. 1 2 B. 1 2 3 C. 1 2 3 4 D. 1 2 3 4 5 9 / 15 9. Find the output of the following code. import java.util.*; class Collection_iterators { public static void main(String 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.sort(list); while(i.hasNext()) System.out.print(i.next() + " "); } } A. 1 2 5 8 B. 2 1 8 5 C. 1 5 8 2 D. 2 8 5 1 10 / 15 10. What is Recursion in Java? A. Recursion is a class B. Recursion is a process of defining a method that calls other methods repeatedly C. Recursion is a process of defining a method that calls itself repeatedly D. Recursion is a process of defining a method that calls other methods which in turn call again this method 11 / 15 11. Find the output of the following program. class increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } A. 32 B. 25 C. 24 D. 33 12 / 15 12. 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 13 / 15 13. What will be the output of the following Java code? class Output { public static void main(String args[]) { Integer i = new Integer(257); byte x = i.byteValue(); System.out.print(x); } } A. 257 B. 256 C. 1 D. O 14 / 15 14. What is Truncation in Java? A. Floating-point value assigned to an integer type B. Integer value assigned to floating type C. Floating-point value assigned to a Floating type D. Integer value assigned to an integer type 15 / 15 15. Which of these method of Object class can clone an object? A. Objectcopy() B. copy() C. Object clone() D. clone() Your score is The average score is 34% LinkedIn Facebook Twitter VKontakte 0% Restart quiz