interface LangFunction
{
void callMe();
}
class HackerEarth{
public static void main(String args[])
{
String str =
"Hacking";
LangFunction if () -> System.out.println(str+"java");
str="ay";
Lf.callme();
}
}
Answers
Answer:
j,b,c are the lengths of the sides as shown in
the figure. Write the following ratios,
(i) sin X (ii) tan Z (iii) cos X (iv) tan X.
Answer
1)sin X=opposite side ofangle X
Hypotenuse
Answer:
Given program:
interface LangFunction
{
void callMe();
}
class HackerEarth
{
public static void main(String []args)
{
String str = "Hacking";
LangFunction Lf = ()-> System.out.println(str+ "java");
str = "ay";
Lf.callMe();
}
}
If we will execute the above program, then we will get an error.
error: local variables referenced from a lambda expression must be final or effectively final
LangFunction Lf = ()-> System.out.println(str+ "java");
This is because all the attributes in an interface are by default public, static and final.
So, we need to make str variable final.
After some changes in the program:
interface LangFunction
{
void callMe();
}
class HackerEarth
{
public static void main(String []args)
{
final String str = "Hacking";
LangFunction Lf = ()-> System.out.println(str+ "java");
str = "ay";
Lf.callMe();
}
}
Although we have made the str variable final. Still we are getting error while compilation.
error: cannot assign a value to final variable str
str = "ay";
This is because we are trying to change the value of a final variable. We cannot do so.
To remove the error, just comment out that statement.
After these changes:
interface LangFunction
{
void callMe();
}
class HackerEarth
{
public static void main(String []args)
{
final String str = "Hacking";
LangFunction Lf = ()-> System.out.println(str+ "java");
//str = "ay";
Lf.callMe();
}
}
The above program will execute properly without any error and we will get an output.
Output: Hackingjava