Question 1
class Base {
public void show() {
System.out.println(\"Base::show() called\");
}
}
class Derived extends Base {
public void show() {
System.out.println(\"Derived::show() called\");
}
}
public class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
Question 2
Question 3
final class Complex {
private final double re;
private final double im;
public Complex(double re, double im) {
this.re = re;
this.im = im;
}
public String toString() {
return \"(\" + re + \" + \" + im + \"i)\";
}
}
class Main {
public static void main(String args[])
{
Complex c = new Complex(10, 15);
System.out.println(\"Complex number is \" + c);
}
}
Question 4
class Base {
final public void show() {
System.out.println(\"Base::show() called\");
}
}
class Derived extends Base {
public void show() {
System.out.println(\"Derived::show() called\");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();;
b.show();
}
}
Question 5
class Base {
public static void show() {
System.out.println(\"Base::show() called\");
}
}
class Derived extends Base {
public static void show() {
System.out.println(\"Derived::show() called\");
}
}
class Main {
public static void main(String[] args) {
Base b = new Derived();
b.show();
}
}
Question 9
abstract class demo
{
public int a;
demo()
{
a = 10;
}
abstract public void set();
abstract final public void get();
}
class Test extends demo
{
public void set(int a)
{
this.a = a;
}
final public void get()
{
System.out.println(\"a = \" + a);
}
public static void main(String[] args)
{
Test obj = new Test();
obj.set(20);
obj.get();
}
}
There are 50 questions to complete.