Menu
Question Index
...

What will be the output of the following program?

class Interest
{
    double amount, rate, interest = -1.0;
    static int numberOfYears;

    public static void main(String[] args)
    {
        Interest i = new Interest();
        System.out.println("i = " + i.interest);
        i.amount = 3000;
        i.rate = 4.25f;
        i.numberOfYears = 2;
        i.interest = 0;
        updateInterest(i);
        System.out.println("i = " + i.interest);
    }

    private static void updateInterest(Interest i)
    {
        System.out.println("i = " + i.interest);
        i.interest = i.amount * i.rate * i.numberOfYears / 100.0;
    }
}


i = -1.0
i = 0.0
i = 255.0
i = -1.0
i = 0.0
i = 0.0
i = -1.0
i = 0.0
i = 25500.0
Compilation Error
Throws NullPointerException

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App