I want to access the variable 's' using the array of objects 'arr'? Please refer the code snippet.
public class Array_Chp3 {
public static void main(String[] args) {
Array_Chp3[] arr = new Array_Chp3[3];
arr[0] = new str(); // when used this line instead of the below line , getting the error "s cannot be resolved or is not a field"
//arr[0] = new Array_Chp3(); // when used this line instead of the above line, getting the error s cannot be resolved or is not a field
str obj = new str();
System.out.println(arr[0]);
System.out.println(arr.length);
System.out.println(arr[0].s); // How to access the variable 's'?
}
}
class str extends Array_Chp3{
public String s = "string123 @ str";
}
Error Message: Exception in thread "main" java.lang.Error: Unresolved compilation problem: s cannot be resolved or is not a field at Array_Chp3.main(Array_Chp3.java:17)