Menu
Topics Index
...
`

Interfaces Simulate Multiple Inheritance


If you need explanation Read this topic

If you need Answer Take test on this topic

Interfaces Simulate Multiple Inheritance
What will be the output of the following program?
public class CricketPlayersUsingInterfaces {
    public static void main(String s[]) {
        StrongBatsmen sachin = new StrongBatsmen("Sachin", 100, 326);
        sachin.makeCentury();
        sachin.takeWickets();
        StrongBatsmen gambhir = new StrongBatsmen("Gambhir", 25);
        gambhir.makeCentury();
    }
}
class StrongBatsmen implements IBatsmen, IBowler {
    int numberOfCenturies;
    String name;
    int wickets;
    StrongBatsmen(String name, int numberOfCenturies, int wickets) {
        this.numberOfCenturies = numberOfCenturies;
        this.wickets = wickets;
        this.name = name;
    }
    StrongBatsmen(String name, int numberOfCenturies) {
        this.numberOfCenturies = numberOfCenturies;
        this.name = name;
    }
    public void makeCentury() {
        System.out.println(name + " made " + numberOfCenturies + " centuries.");
    }
    public void takeWickets() {
        System.out.println(name + " taken " + wickets + " wickets.");
    }
}
interface IBatsmen {
    void makeCentury();
}
interface IBowler {
    void takeWickets();
}

A. Sachin made 100 centuries.
Sachin taken 326 wickets.
Gambhir made 25 centuries.
B. Sachin made 100 centuries.
Sachin taken 326 wickets.
Sachin made 100 centuries.
Gambhir made 25 centuries.
C. Compilation Error
D. Runtime Error
Topic: Java Interface

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is A. First object sachin is created and the corresponding values are printed using the two methods( from the two interfaces) and the first constructor. Second gambhir object is created with the given values.

Posted by Nikhil Sulibhavi    2014-08-11 13:00:52


Ais ans.as StrongBatsmen ojct is created n makecnty n take wickets  r called. nxt other objct of ghamrbir is taken and the rest is done same

Posted by Shabaaz Shaikz    2014-08-11 13:01:51


a

Posted by Zeg Abder    2014-08-11 13:57:37


Congratulations Nikhil Sulibhavi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-08-12 04:10:10


© meritcampus 2019

All Rights Reserved.

Open In App