Set 3
Set 3
1.class S{
public static void main(String arg[])
{
Object o1=2.3;
System.out.println(o1.floatValue()+1);
}
}
What is output of above program
A.Compilation error
B.2.4
C.3.3
D.3.4
2.Can an Object of a Child type be assigned to a variable of the parent type? For example.
Card crd;
BirthDay bd= new BirthDay(“Lucinda”,42);
crd = bd; // is this correct?
A.No-there must aways be an exact match between the variable and the object types.
B.No-but a Object of parent type can be assigned to a variable of child type
C.Yes-an object can be assigned to a reference variable of the parent type.
D.Yes-any object can be assigned to any reference variable.
True
False
7. Junit is ________
A.a product trom Jakarta
B.a product trom Apache
C.an Opensource testing framework
D.None of the above
8.What will be the result of attempting to compile and run the following program?
public class Polymorphism {
public static void main(String[]args) {
A refl = new C();
B ref2 = (B) refl;
System.out.println(ref2.f());
}
}
class A { int f() { return 0; ) }
class B extends A { int f() { return 1; } )
class C extends B { int f() { return 2; ) }
10.Can an abstract class define both abstract methods and non-abstract methods ?
A.No-it must have all one or the other.
B.No-it must have all abstract methods.
D.Yes-the child classes inherit both.
12.
public class Demo (
pubbc static void main(String args[])
{
for(int I=1;I<=5;I++)
{
for(int j=0;j<I;j++)
{
System.out.println(“*”);
}
System.out.println(‘*’);
}
}
}
A. *
**
***
****
*****
B. *****
****
***
**
*
D.Compilation error
A.The signature of a method is the name of the method and the type of its return value.
B.The signature of a method is the name of the method and the names of its parameters.
C.The signature of a method is the name of the method and the data types of its parameters.
D.The signature of a method is the name of the method, its parameter list, and its return type.
22.Say that class Rodent has a child class Rat and another child class Mouse. Class Mouse has a child
class PocketMouse. Examine the following
Rodent rod;
Rat rat new Rat();
Mouse mos= new Mouse();
PocketMouse pit new PocketMouse();
Which one of the following will cause a compiler error?
a.rod=rat;
b.rod=mos;
c.pkt=null;
d.pkt=rat;
25.What will be the result of attempting to compile and run the following program?
public class Polymorphism2 {
System.out.println(ref2.g());
}
}
class A (
class B extends A {
private int f() { return 1;) public int g() { return f();)
class C extends B{
The program will compile without error and print 0 when run.
The program will compile without error and print 1 when run.
The program will compile without error and print 2 when run.
The program will compile without error and print 3 when run.
26.what is CLASSPATH?
a.An environment variable which is used by the Java compiler look for the Java source files.
b.An environment variable which is used by the Java compiler and the JVM to look for
the dependent Java class files.
c.An environment variable which stores the path of the Java compiler.
d.An environment variable which stores the path of the Java interpreter.