Menu
Question Index
...

What will be the output of the following program?

class ConvertTemp
{

    double c;
    double f;

    ConvertTemp(double c, double f)
    {
        this.c = c;
        this.f = f;
    }

    public static void main(String[] args)
    {
        ConvertTemp c = new ConvertTemp(35, 0);
        convert(c);
        System.out.println(c.f + " fahrenheit is same as " + c.c + " celsius");
    }

    public static void convert(ConvertTemp c)
    {
        c.f = c.c * 9 / 5 + 32;
    }
}


95.0 fahrenheit is same as 0.0 celsius
95.0 fahrenheit is same as 35.0 celsius
35.0 fahrenheit is same as 95.0 celsius
Compilation Error - since the non-static variables c and f can not be accessed from static method.
Compilation Error for some other reason

Doubts

Problems

Topic: this Keyword In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App