Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Q4. What will be the result of compiling and running the following code?
class Base{
public short getValue(){ return 1; } //1
}
class Base2 extends Base{
public byte getValue(){ return 2; } //2
}
public class TestClass{
public static void main(String[] args){
Base b = new Base2();
System.out.println(b.getValue()); //3
}
}
Select 1 option
A. It will print 1
B. It will print 2.
C. Compile time error at //1
D. Compile time error at //2
Select 1 option
A. public class ImaginaryNumber extends Number {
}
B. public class ThreeWayBoolean extends Boolean {
}
C. public class NewSystem extends System {
}
D. public class ReverseString extends String {
}
Q6. class A {
public static void f(){
System.out.println(“fA”); }}
class B extends A{
public void f(){
System.out.println(“fB”); }
public static void main(String[] args) {
A a= new B();
a.f(); }}
What will happen on compilation or execution of code?
A. fA
B. fB
C. Code will not compile
D. Code will throw runtime error
Q7. What will be the result of attempting to compile and run the following program?
public class TestClass{
public static void main(String args[ ] ){
A o1 = new C( );
B o2 = (B) o1;
System.out.println(o1.m1( ) );
System.out.println(o2.i );
}
}
Q14. . Given:
class Rocket {
private void blastOff() { System.out.print("bang "); }
}
public class Shuttle extends Rocket {
public static void main(String[] args) {
new Shuttle().go();
}
void go() {
blastOff();
// Rocket.blastOff(); // line A
}
private void blastOff() { System.out.print("sh-bang "); }
}
Which are true?
A. As the code stands, the output is bang
B. As the code stands, the output is sh-bang
C. As the code stands, compilation fails.
D. If line A is uncommented, the output is bang bang