Sail E0 Webinar

MCQs

Total Questions : 31 | Page 3 of 4 pages
Question 21. 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.    two one one
  2.    one one two
  3.    one Exception
  4.    Compilation Error
  5.    None of these
 Discuss Question
Answer: Option D. -> Compilation Error
Question 22. 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 1
m.call(); //line 2
}
}
  1.    One
  2.    Compilation fails due to an error on line 1
  3.    Compilation fails due to an error on line 2
  4.    Compilation succeed but no output.
 Discuss Question
Answer: Option B. -> Compilation fails due to an error on line 1
Question 23. 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.    1
  2.    2
  3.    3
  4.    Compilation Error
  5.    None of these
 Discuss Question
Answer: Option B. -> 2
Question 24. Public class MyClass{ }
For the above class(MyClass) what is the correct way of declaring constructor?
  1.    MyClass(){}
  2.    MyClass(void) {}
  3.    public MyClass(){}
  4.    public MyClass(void){}
  5.    1 and 3
 Discuss Question
Answer: Option E. -> 1 and 3
Question 25. 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.    Compile fail due to error on line no 2
  2.    Compile fail due to error on line no 9
  3.    Compile fail due to error on line no 8
  4.    15
  5.    None of these
 Discuss Question
Answer: Option B. -> Compile fail due to error on line no 9
Question 26. What will be the output?
public class Test{
public static void main(String[] args){
String value = "abc";
changeValue(value);
System.out.println(value);
}
public static void changeValue(String a){
a = "xyz";
}
}
  1.    abc
  2.    xyz
  3.    Compilation fails
  4.    Compilation clean but no output
  5.    None of these
 Discuss Question
Answer: Option A. -> abc
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.    long
  2.    int
  3.    Compilation fails
  4.    Compilation clean but throws RuntimeException
  5.    None of these
 Discuss Question
Answer: Option B. -> 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.    A 5 B 8
  3.    A B 5
  4.    B 8 A 5
  5.    None of these
 Discuss Question
Answer: Option A. -> A B 8
Question 29. 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 here
8. }
9. }
Which of the below code can be insert at line 7 to make clean compilation ?
  1.    A a = new B();
  2.    A a = new B(5);
  3.    A a = new A(String s);
  4.    All of the above
  5.    None of these
 Discuss Question
Answer: Option A. -> A a = new B();
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 examveda() {} throws IOException
  2.    void examveda() throws IOException{}
  3.    void examveda() throw IOException{}
  4.    void examveda(void) throws IOException{}
  5.    examveda() throws IOException{}
 Discuss Question
Answer: Option B. -> void examveda() throws IOException{}

Latest Videos

Latest Test Papers