Computer Applications
What is the output of the following code ?
void func(String s) {
String s = s1 + "xyz" ;
System.out.println("s1 =" + s1) ;
System.out.println("s =" + s) ;
}
Java
User Defined Methods
5 Likes
Answer
The given code generates error because of the following :
- String s is already declared in the function signature. Its redeclaration inside func() will cause a compile time error.
- String s1 is not declared and that is also a compile time error.
Answered By
4 Likes
Related Questions
How does the compiler interpret more than one definitions having same name ? What steps does it follow to distinguish these ?
Discuss how the best match is found when a call to an overloaded method is encountered. Give example(s) to support your answer.
Design a class to overload a function area( ) as follows:
- double area (double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2 - double area (int a, int b, int height) with three integer arguments, returns the area of a trapezium using the formula:
area = (1/2)height(a + b) - double area (double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
area = 1/2(diagonal1 x diagonal2)
- double area (double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
What is the output of the following program?
class AllStatic { static int m = 0 ; static int n = 0 ; public static void main(String[ ] args) { int m = 10; int x = 20; { int n = 30 ; System.out.println("m + n =" + m + n) ; check(5) ; } x = m + n; System.out.println("x =" + x) ; } public static void check int k ; { int m = 5 ; n = k; System.out.println("m is " + m) ; System.out.println("n is " + n) ; } }