Given:
1. import java.util.*; 2. class Shape { 3. String getFreq() { return "12.3"; } 4. static String getF() { return "12.3"; } 5. } // w w w .j av a 2s . com 6. class Main extends Shape { 7. String getFreq() { return "3.21"; } 8. static String getF() { return "3.21"; } 9. public static void main(String[] args) { 10. List<Shape> radios = new ArrayList<Shape>(); 11. radios.add(new Shape()); 12. radios.add(new Main()); 13. for(Shape r: radios) 14. System.out.print(r.getFreq() + " " + r.getF() + " "); 15. } }
What is the result?
E is correct.
The important point is that the getF()
methods are static.
static methods CANNOT be overridden, but they can be redefined, as is the case in this code.