Menu
Topics Index
...
`

Calculate Area


If you need explanation Read this topic

If you need Answer Take test on this topic

Calculate Area
What will be the output of the following program.
class CalculateArea
{
    public static void main(String s[])
    {
        int width = 20;
        int breadth = 30;
        int area = 0;
        
        calculateArea(width, breadth, area);

        System.out.println("Area : " + area);
    }

    public static void calculateArea(int width, int breadth, int area)
    {
        area = width * breadth;
    }
}

A. Area : 0
B. Area : 600
C. Compilation Error - since we can not pass value 0 to a method.
D. Compilation Error - since we are not returning the area from the method
Topic: Is Java Pass by Reference or Pass by Value

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 A..here we have the concept of passing parameters and the returning the values...

we have the 2 types of parameter passing in java
Call by value: in this type changes made in the formal arguments will not be effect to the actual aruments..
Ex: void one(int a) here a is formal argument
one(x)--  x is the actual argument

Cabb by reference:in this type changes made in the formal arguments will  be effected to the actual aruments..
one(new Student());
void one(Student s);

here have the concept of the call by value..here we have the calArea method which takes 3 arguments..in this method we are assigning area=w*b..this effect will not applied to the variable in the main()..Bcz it call by value..
So area in the main will remain same as 0...so here output is 0..

Posted by Uday Kumar    2014-12-10 03:58:59


Ans is 0
When value of formal parameters changed it will not effect the actual parameters. a=w*b is formal parameters and it will not change the area. So Area will take actual value mentioned as '0'

Posted by Fuzail Ahmed    2014-12-10 05:56:12


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 Uday Kumar. 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-11 05:14:42


© meritcampus 2019

All Rights Reserved.

Open In App