java exam 0 votes, 0 avg 7 123456789101112131415 Java Questions 1 / 15 1. What will be the output of the following Java code? class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } } A. 11 B. 10 C. 13 D. 14 2 / 15 2. Find the output of the following code. class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Quiz"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } A. QuizziuQ B. ziuQQuiz C. Quiz D. ziuQ 3 / 15 3. 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(); 4 / 15 4. 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 5 / 15 5. From the following statements which is a disadvantage of an java array? A. An array can hold primitive types data B. An array has its size that is known as array length C. An array knows only its type that it contains. Array type is checked at the compile-time D. An array holds only one type of data 6 / 15 6. Which of these is not a correct statement? A. Every class containing abstract method must be declared abstract B. Abstract class defines only the structure of the class not its implementation C. Abstract class can be initiated by new operator D. Abstract class can be inherited 7 / 15 7. Which of these statements are incorrect? A. The left shift operator, <<, shifts all of the bits in a value to the left specified number of times B. The right shift operator, >>, shifts all of the bits in a value to the right specified number of times C. The left shift operator can be used as an alternative to multiplying by 2 D. The right shift operator automatically fills the higher order bits with 0 8 / 15 8. What will be the output of the following Java program? class A { int i; public void display() { System.out.println(i); } } class B extends A { int j; public void display() { System.out.println(j); } } class Dynamic_dispatch { public static void main(String args[]) { B obj2 = new B(); obj2.i = 1; obj2.j = 2; A r; r = obj2; r.display(); } } A. 1 B. 2 C. 3 D. 4 9 / 15 9. Which of these method of class String is used to remove leading and trailing whitespaces? A. startsWith() B. trim() C. Trim() D. doTrim() 10 / 15 10. 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 11 / 15 11. Which of these is correct about passing an argument by call-by-value process? A. Copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument B. Copy of argument is made into the formal parameter of the subroutine C. Reference to original argument is passed to formal parameter of the subroutine D. Reference to original argument is passed to formal parameter of the subroutine and changes made on parameters of subroutine have effect on original argument 12 / 15 12. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction? A. Declare the method with the keyword protected B. Declare the method with the keyword private C. Do not declare the method with any accessibility modifiers D. Declare the method with the keyword public and private. 13 / 15 13. The concept of multiple inheritances is implemented in Java by I. Extending two or more classes. II. Extending one class and implementing one or more interfaces. III. Implementing two or more interfaces. A. (II) and (III) B. Only (II) C. (I) and (II) D. Only (III) 14 / 15 14. Which concept of Java is achieved by combining methods and attribute into a class? A. Encapsulation B. Inheritance C. Polymorphism D. Abstraction 15 / 15 15. 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 Your score is The average score is 19% LinkedIn Facebook Twitter VKontakte 0% Restart quiz