Posts

Showing posts from December, 2019

Write Output of Java Program - Exam Sample Questions

Answers are given at end. 1 public class StringTest { public static void main(String args[]){ String t1=new String("Text"); String t2=new String("Text"); System.out.println(t1==t2); String t3="Text"; String t4="Text"; System.out.println(t3==t4);   System.out.println(t1==t4); System.out.println(t1.equals(t3)); } } 2 public class ExceptionTest {  public static void main(String[] args) {      try { System.out.println("Welcome to Java"); int[] a = new int[10]; a[10] = 1; System.out.println("Welcome to Python");     } catch (Exception ex) { System.out.println("There is an exception”);     }     System.out.println("Bye.");  } } 3 class A{     public int x = 1; public A(int i){ x += i; } } class B extends A { public B(int i){ super(i); x += i; } } public class  Test{ public static void main(String args[]) {     A arr[] = new A[2];

Object Oriented Programming OOP Multiple Choice Questions MCQ - Samples for Exam

There are 60 questions in this post. Set 1 containd 30 and Set 2 also contains 30. Solutions of each set is given after each set of questions. Questions Set 1: 1.What is the output of the following code? 1: public class ArithmeticSample { 2: public static void main(String[] args) { 3: int x = 5 * 4 % 3; 4: System.out.println(x); 5: }} A. 2 B. 3 C. 5 D. 6 E. The code will not compile because of line 3. 2. What is the output of the following code snippet? 3: int x = 4; 4: long y = x * 4 - x++; 5: if(y<10) System.out.println("Too Low"); 6: else System.out.println("Just right"); 7: else System.out.println("Too High"); A. Too Low B. Just Right C. Too High D. Compiles but throws a NullPointerException. E. The code will not compile because of line 6. F. The code will not compile because of line 7. 3. Given the following classes, what is the maximum number of imports that can be removed and have th