Menu
Topics Index
...
`

Sixes More Sixes and Dhoni2963


If you need explanation Read this topic

If you need Answer Take test on this topic

Sixes More Sixes and Dhoni2963
What will be the output of the following program?
interface SixesMachine {
    void hitSixes();
}

public abstract class DhoniInTheMaking implements SixesMachine {
    public String numberOfSixes() {
        return "6 0 6 3 6 6 6 6";
    }
    public void printRunsTrail(String runsAndRuns) {
        System.out.println(runsAndRuns);
    }
}

class Dhoni extends DhoniInTheMaking {
    public static void main(String args[]) {
        DhoniInTheMaking outputClass = new Dhoni();
        outputClass.hitSixes();
    }
    public void hitSixes() {
        numberOfSixes().substring(5, 12);
        printRunsTrail(numberOfSixes().substring(4, 7));
    }
}

A. 6 0 6 3 6 6 6 6
B. 6 3
C. 6 6
D. Compilation Error or Runtime Error
Topic: Difference Between Interfaces And Abstract Classes

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 B..here we have the concept of abstract classes and interfaces..
abstract class is an class which contains the abstract methods and normal methods..
void one();--->abstract method
void one(){}--> normal method..
abstract methods will use full to act like a place holders in the parent class..
we cant create the instance for the abstract class but we can create reference for it...

if an class has only abstract methods than we can write it as interface...interfaces dont have normal methods...

Execution:
here we have interface SixesMachine as interface with hitSixes() as abstract method
DhoniInMaking class implementing the these interfaced but we did not override the hitSixes() thats y we made this class as abstract..
classs Dhoni extending the DhoniInTheMaking class and this class overriding the hitSixes()...in main() we create reference for DhoniInTheMaking instance for the Dhoni and calling the hitSixes() so method in Dhoni class get executed and these we are sending the substring of 4,7 which is 6,3 so we are printing this string in printTrail()

Posted by Uday Kumar    2014-12-16 09:43:05


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Maheshwari Natarajan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-17 06:55:39


© meritcampus 2019

All Rights Reserved.

Open In App