import java.util.regex.*;
public class Media{
String s = " radio1 radiowave radiation" ;
public static void main(String argv[]){
new Media();
}
Media(){
String regex = "radio\\d";
Pattern pattern = Pattern.compile(regex);
Matcher matcher =pattern.matcher(s);
while(matcher.find()){
System.out.print(matcher.group());
}
}
}
1)Compile time error, attempt to access a non existant Pattern instance.
2 Compilation and output of radio at runtime
3 Compilation and output of radio1radiowave at runtime
4 Compilation and output of radio1 at runtime
Will this work? If yes , y? I had read that we cannot invoke constructors.
The correct answer is 4 but i didnt understand it so pls help me.