Menu
Question Index
...

What will be the output of the following program?

public class AccountTest {
    public static void main(String[] args) {
    Account account = new Account();
    account.credit(200, "15-Oct-2013", "Hyderabad").print();
    account.debit(50, "16-Oct-2013", "Warangal").print();
    account.debit(75, "18-Oct-2013", "Guntur").print();
    account.credit(15, "18-Oct-2013", "Khammam").print();
    }
}
class Account {
    double amount;
    String lastTransactionDate, lastLocation;
    int numberOfTranscations;
    Account credit(double amount, String date, String location) {
        numberOfTranscations++;
        lastTransactionDate = date;
        lastLocation = location;
        amount += amount;
        return this;
    }
    Account debit(double amount, String date, String location) {
        if (this.amount >= amount) {
            numberOfTranscations++;
            lastTransactionDate = date;
            lastLocation = location;
            amount -= amount;
            return this;
        }
        return null;
    }
    void print() {
        System.out.println(numberOfTranscations + ". " + lastTransactionDate + " at " + lastLocation + " : " + amount);
    }
}


1. 15-Oct-2013 at Hyderabad : 200.0
2. 16-Oct-2013 at Warangal : 150.0
3. 18-Oct-2013 at Guntur : 75.0
4. 18-Oct-2013 at Khammam : 90.0
1. 15-Oct-2013 at Hyderabad : 200.0
2. 16-Oct-2013 at Warangal : 150.0
3. 18-Oct-2013 at Guntur : 75.0
4. 18-Oct-2013 at Khammam : 60.0
1. 15-Oct-2013 at Hyderabad : 200.0
2. 16-Oct-2013 at Warangal : 50.0
3. 18-Oct-2013 at Guntur : 75.0
4. 18-Oct-2013 at Khammam : 15.0
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Behavior Of Java Classes Using Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App