Java OOPs Program Test-3

What will be the output of the following java code?

class Hello {

public int data = 8;

public String show() {

return "Hello";

}

}

class Test extends Hello {

public int data = 9;

public String show() {

return "Test";

}

public static void main(String[] args) {

Hello h = new Test();

System.out.println(h.data + " " + h.show());

}

}

Which code, when inserted at line 1, will cause a Exception ?

class A {}

class A1 extends A {}

class A2 extends A {}

public class Test {

public static void main(String args[]) {

A a = new A();

A1 a1 = new A1();

A2 a2 = new A2();

// insert line 1 code here

}

}

Which line of code inserted for complete executions?

class Hello {

private String name;

public Hello(String name) {

this.name = name;

}

public String getName() {

return name;

}

}

public class Test extends Hello {

public void parent() {

}

public void child() {

}

}

What will be the output of the following java code?

class Hello {

public int number;

protected Hello(int number) {

this.number = number;

}

}

public class Test extends Hello {

private Test(int number) {

super(number);

}

public static void main(String[] args) {

Test t = new Test(500);

System.out.print(t.number);

}

}

What will be the output of the following java code?

class Hello {

private static int multiply(int a, int b) {

return a * b;

}

}

public class Test extends Hello {

public static int multiply(int a, int b) {

int m = super.multiply(a, b);

return m;

}

public static void main(String[] args) {

Test t = new Test();

System.out.println(t.multiply(5, 2));

System.out.println(Test.multiply(8, 3));

}

}