Originally posted by Willie Toma: [B]What is the reasoning behind the output? It uses the variable of the base class. [/B]
Hello, This seems to be a very common question that is asked. As far as I know, the output should be: 99 RType.amethod() This actually happens because methods are determined at runtime while variables are determined at compile time. Which means that while the program is compiling, it sets the data of any/all the variables which are defined in the program. The data of methods however, is determined at runtime, so the compiler sees that RType extends Base, so it uses the data of amethod from the RType class, and not the Base class. P.S: Be careful of these sort of questions as they are often tricky and misleading, and also you can only define a object of a class in this way if the class is extended; inner classes are different you need to use: outerclass.innerclass obj = new outer().new inner() Someone please correct me if im wrong. Kamil.