ICSE Class 10 Computer Applications Question 43 of 43

User-Defined Methods — Question 43

Back to all questions
43
Question

Question 41

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) ;
}
Answer

The given code generates error because of the following :

  1. String s is already declared in the function signature. Its redeclaration inside func() will cause a compile time error.
  2. String s1 is not declared and that is also a compile time error.