Question
What will the following program display? public class checkpoint { public static void main(String urgs[]) { int n = 1776; doubled = 110.0901; System .out.println(n + + d); myMethod(n, d); System.out.println(n + + d); } public static void myMethod(int i, double x) { System.out.printing + + x); i = 1250; x= 199.99; System.out.println(i + " + x); } } Write the following two methods: i. compute Diameter; This method accepts the radius (r) of a circle, and returns diameter (2*r; radius = 2.5). Declare all variables used here & initialize radius: __________ Show method call: ________ Write method code here:
Explanation / Answer
Q-12
Answer :
1776 110.0901
1776 110.0901
1250 199.99
1776 110.0901
in Java Primitive variable are copied by value. so when you pass the variable n and d to mymethod new copy of n and d is created and assigned to x and i .
So, 4th line output is 1776 110.0901
Q - 13