2009-07-02

Java single inheritance questions


There are few structures in Java that are not so intuitive as others. Take a look:
public class InnerInvocation {

 String getValue() {
  return "Outer Value";
 }

 private class InnerClass {
  String getValue() {
   return "Inner Value";
  }

  void work() {
   // insert code here
  }
 }
}

What code do you need to invoke getValue() method from outer class?

Here is the answer:
  void work() {
   InnerInvocation.this.getValue();
  }

And now the question of the day: there is syntax that possibly can allow multiple inheritance in Java, so why is it forbidden? Because you as developer can make lots of mistakes? Why then they allowed reflections?

No comments: