About Question enthuware.ocpjp.v11.2-.-1770 :
Posted: Sun Apr 18, 2021 5:36 am
I have tried the example and it compiles perfectly. Can you please double check? It uses types from Food class. If you call it like Eatable.types = 30 - then you get an error that you cannot reassign final variable (which types in Eatable is).
Problem statement:
What will the following code print when compiled and run?
Problem statement:
What will the following code print when compiled and run?
Code: Select all
interface Eatable{ int types = 10; }
class Food implements Eatable { public static int types = 20; }
public class Fruit extends Food implements Eatable{ //LINE1
public static void main(String[] args) {
types = 30; //LINE 2
System.out.println(types); //LINE 3
}
}