abstract class questions in java

Objective type questions on abstract class in java and answers


(1)

abstract class Abstract {
    
    public static void main(String[] args){
         System.out.print("It is abstract class");
    }
   
    static{
         System.out.println("Why");
    }
}

What will output when you compile and run the above code?
         
(a) Why
    It is abstract class
(b) It is abstract class
    Why

(c)It is abstract class
(d)Compiler error





Answer: (a)

(2)

abstract class Abstract {
    
    public static void main(String[] args){
         double[] array={1D,2d,3,4.,5.0};
         display(array);
    }
   
    abstract void display();
    static void display(double[] arr){
         for(double d:arr)
         System.out.println(d);
    }
}

What will output when you compile and run the above code?
         
(a) 1.0
    2.0
    3.0
    4.0
    5.0
(b)1.0
(c)5.0
(d)Compiler error





Answer: (a)

 (3)

class Abstract {
    
    public static void main(String[] args){
         float[] array={1F,2f};
         show(array);
    }
   
    abstract void display();
   
    static void show(float[] arr){
         for(int i=0;i<ARR.< span="">length;i++)
         System.out.println(arr[i]);
    }
}

What will output when you compile and run the above code?
         
(a)1.0
   2.0
(b)1.0
(c)1.0
   2.0
   null
(d)Compiler error





Answer: (d)

(4)

abstract class Abstract {
    
    public static void main(String[] args){
         if(new Abstract() instanceof Abstract)
             System.out.print("True");
         else
             System.out.print("False");
        
    }
}

What will output when you compile and run the above code?
         
(a)True
(b)False
(c)Run time exception
(d)Compiler error






Answer: (d)

(5)

abstract class Abstract {
    static int a=3;
    static float b=5.3f;
    Abstract(p,q){
         a=p;
         b=q;
    }
    public static void main(String[] args){
         System.out.print((int)a+~a+b);
        
    }
}

What will output when you compile and run the above code?
         
(a)4.3
(b)4
(c)5
(d)Compiler error






Answer: (d)

No comments: