info@meritcampus.com    +91-85006-22255
...
`

Calculate Area241
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 = calculateArea(width, breadth);        System.out.println("Area : " + area);    }    public static int calculateArea(int width, int breadth)    {        int area = width * breadth;    }}`

 A. Area : 0 B. Area : 600 C. Compilation Error - since we can not have duplicate variable name area in both main method and the calculateArea method. D. Compilation Error - since we are not returning the area from the calculateArea method
Topic:

### User comments below.All of them might not be correct.

ans:d  here it gives compile time error of return statement is missing

Posted by Goutham Singarapu    2015-02-04 09:28:48

why because in calculate area method  return type is int but we are  not return any value from that method thats why option d is correct

Posted by Goutham Singarapu    2015-02-04 09:30:38

Ans is Option D...here Execution starts from main() method here we are declaring variables width, breadth and initialized with the values 20,30 respectively and we are declaring variable area and we are calling calculateArea(width,breadth) with return datatype int  and inside this calculateArea method we are not returning any value to main() method .... that means if you are using int as return datatype it will expect return statement here we are not writing return statement so here compilation error will occur as this method must return  a  result of type int so Ans is Option D...

Posted by Bhagi Bhagyasri    2015-02-04 10:25:13

ANS IS D (Compilation Error as area is not returned,so error will be "MISSING RETURN STATEMENT".

--Here width and breadth variables are declared to 20 and 30 respectively.

--calculateArea() method is called with width and breadth variable and target variable is area which is integer.

--In calculateArea() method,width and breadth are multiplied and assigned to area varible,but area is not retuerned.

--So,There is Compilation Error stating MISSING RETURN STATEMENT.

Posted by Mânïshå Mùlchåndânï    2015-02-04 17:42:37

ans d. compilation error. initially width and breath variable assigned with 20 and 30.variable area is assigned with calculateArea() function call,it pass both width and breadth value as parameters, thn coming to the function definition here we locally defined one area variable and assigned with multiplication of width and breadth. but here function dnt have return statement so compiler throws error because this method doesn't return anything, and the return type is not void .here return type int,it should return  value otherwise compiler throws error

Posted by Maheshwari Natarajan    2015-02-04 17:59:46

d

Posted by Shubham Bansal    2015-02-05 04:07:17

This dose is now closed and the winners are Goutham Singarapu,  for 'First Correct Comment', Bhagi Bhagyasri, Mânïshå Mùlchåndânï, Maheshwari Natarajan,  for 'Best Comment' and Shubham Bansal for the 'Popular Comment'. The 'lucky liker' is Mânïshå Mùlchåndânï. 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    2015-02-05 07:19:00