java exam 0 votes, 0 avg 7 123456789101112131415 Java Questions 1 / 15 1. 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 2 / 15 2. 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 3 / 15 3. 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(); 4 / 15 4. 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 5 / 15 5. 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 6 / 15 6. 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. 7 / 15 7. What will be the output of the following Java code? class San { public void m1 (int i,float f) { System.out.println(" int float method"); } public void m1(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { San s=new San(); s.m1(20,20); } } A. int float method B. float int method C. compile time error D. run time error 8 / 15 8. What is the default value of String variable? A. “” B. '’ C. null D. not defined 9 / 15 9. Which of the following is a superclass of every class in Java? A. ArrayList B. Abstract class C. Object class D. String 10 / 15 10. Which data type value is returned by all transcendental math functions? A. int B. float C. double D. long 11 / 15 11. In Iterator, hasMoreElements() method of Enumeration has been changed to: A. hasNextElement() B. isNext() C. hasNext() D. name remains same 12 / 15 12. Which of these keywords is used to prevent content of a variable from being modified? A. final B. last C. constant D. static 13 / 15 13. Choose the appropriate data type for this field: isSwimmer A. double B. boolean C. string D. int 14 / 15 14. What will be the output of the following Java code? class Char { public static void main(String args[]) { char ch1, ch2; ch1 = 88; // code for X ch2 = 'Y'; System.out.print("ch1 and ch2: "); System.out.println(ch1 + " " + ch2); } } A. ch1 and ch2: X Y B. ch1 and ch2: x y C. ch1 and ch2: 1 3 D. None of the above 15 / 15 15. Which of these keywords are used for the block to be examined for exceptions? A. check B. throw C. catch D. try Your score is The average score is 19% LinkedIn Facebook Twitter VKontakte 0% Restart quiz