Sail E0 Webinar

MCQs

Total Questions : 30 | Page 3 of 3 pages
Question 21. What is the output for the below code ?1. public class A{2. int add(int i, int j){3. return i+j;4. }5. }6. public class B extends A{7. public static void main(String argv[]){8. short s = 9;9. System.out.println(add(s,6));10. }11.}
  1.    15
  2.    None of these
  3.    Compile fail due to error on line no 2
  4.    Compile fail due to error on line no 9
  5.    Compile fail due to error on line no 8
 Discuss Question
Answer: Option D. -> Compile fail due to error on line no 9
Question 22. Determine output:public class Test{ public static void main(String args[]){ MyClass obj = new MyClass(); obj.val = 1; obj.call(obj); System.out.println(obj.val); }}class MyClass{ public int val; public void call(MyClass ref){ ref.val++; }}
  1.    None of these
  2.    Compilation Error
  3.    1
  4.    3
  5.    2
 Discuss Question
Answer: Option E. -> 2
Question 23. Class MyClass{      MyClass(){            System.out.print("one");      }      public void myMethod(){            this();            System.out.print("two");      }} public class TestClass{      public static void main(String args[]){            MyClass obj = new MyClass();            obj.myMethod();      }}
  1.    one one two
  2.    Compilation Error
  3.    one Exception
  4.    two one one
  5.    None of these
 Discuss Question
Answer: Option B. -> Compilation Error
Question 24. Public class MyClass{ }For the above class(MyClass) what is the correct way of declaring constructor?
  1.    public MyClass(){}
  2.    MyClass(void) {}
  3.    MyClass(){}
  4.    1 and 3
  5.    public MyClass(void){}
 Discuss Question
Answer: Option D. -> 1 and 3
Question 25. Class MyClass{int i;int j;public MyClass(int i, int j){this.i = i;this.j = j;}public void call(){System.out.print("One");}}public class Test{public static void main(String args[]){MyClass m = new MyClass(); //line 1m.call(); //line 2}}
  1.    Compilation fails due to an error on line 1
  2.    Compilation succeed but no output.
  3.    Compilation fails due to an error on line 2
  4.    One
 Discuss Question
Answer: Option A. -> Compilation fails due to an error on line 1
Question 26. Class A{ A(String s){} A(){}}1. class B extends A{2. B(){}3. B(String s){4. super(s);5. }6. void test(){7. // insert code here8. }9. }Which of the below code can be insert at line 7 to make clean compilation ?
  1.    A a = new A(String s);
  2.    A a = new B(5);
  3.    All of these
  4.    A a = new B();
  5.    None of these
 Discuss Question
Answer: Option D. -> A a = new B();
Question 27. What is the output for the below code?public class Test{ public static void printValue(int i, int j, int k){ System.out.println("int"); } public static void printValue(byte...b){ System.out.println("long"); } public static void main(String... args){ byte b = 9; printValue(b,b,b); }}
  1.    Compilation clean but throws RuntimeException
  2.    None of these
  3.    int
  4.    Compilation fails
  5.    long
 Discuss Question
Answer: Option C. -> int
Question 28. What is the output for the below code ?class A{ public A(){ System.out.println("A"); } public A(int i){ this(); System.out.println(i); }}class B extends A{ public B(){ System.out.println("B"); } public B(int i){ this(); System.out.println(i+3); }}public class Test{ public static void main (String[] args){ new B(5); }}
  1.    A B 8
  2.    None of these
  3.    B 8 A 5
  4.    A 5 B 8
  5.    A B 5
 Discuss Question
Answer: Option A. -> A B 8
Question 29. What will be the result of compiling and running the given code?class A{ int b=10; private A(){ this.b=7; } int f(){ return b; }}class B extends A{ int b;}public class Test{ public static void main(String[] args){ A a = new B(); System.out.println(a.f()); }}
  1.    Compilation Fails
  2.    Prints 0
  3.    Prints 7
  4.    None of these
  5.    Prints 10
 Discuss Question
Answer: Option A. -> Compilation Fails
Question 30. Which of these is a legal definition of a method named examveda assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
  1.    void examians() throws IOException{}
  2.    void examians() throw IOException{}
  3.    void examians() {} throws IOException
  4.    examians() throws IOException{}
  5.    void examians(void) throws IOException{}
 Discuss Question
Answer: Option A. -> void examians() throws IOException{}

Latest Videos

Latest Test Papers