Menu
Question Index
...

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();
}


Sachin made 100 centuries.
Sachin taken 326 wickets.
Gambhir made 25 centuries.
Sachin made 100 centuries.
Sachin taken 326 wickets.
Sachin made 100 centuries.
Gambhir made 25 centuries.
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Interface

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App