Objective type questions on abstract class in java and answers
(1)
(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)
Java questions of data types and answer
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
Java questions on if else statements
Java questions on switch case and answers
Java questions on looping and answers
Java questions on characters
Java questions on strings and answers
Java questions on variables and answers
Java questions on automatic type promotions
Java questions on bit wise operator
Java questions on operators and answers
Java questions on static keyword and answers
Java questions on super keyword and answers
Java questions on abstract class an answers
Java questions on interface and answers
Java questions on enum data type and answers
Java questions on break and continue keyword
Java questions of primitive data types
Java questions on conditional operators
Java questions on two dimensional array and answers
No comments:
Post a Comment