write a program to implement the above interface using Lambda Expression to accept “ Hello World” and print it 10 times.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
write a program to implement the above interface using Lambda Expression to accept “ Hello World” and print it 10 times.
write a program to implement the above interface using Inner Class to accept “ Hello World” and print it 10 times
This is my code
interface interf1 {
publicvoidrepeat(Strings1);
}
public class Main {
public static void main(String[] args) {
interf1 obj = (s1)-> { //using lambda expression
for(int i=0;i<10;i++) {
System.out.println(s1);
}
};
obj.repeat("Hello World");
}
}
public class Assignment {
public static void main(String[] args) {
interf1 obj = new interf1() { //inner class
public void repeat(String s1){
for(int i=0;i<10;i++){
System.out.println(s1);
}
}
};
obj.repeat("Hello World"); //function call
}
}
But i keep getting this error
Step by step
Solved in 3 steps with 3 images