Question: Suppose a class MyClass implements an interface MyInterface, and it has its own instance method let's say foo().
When i create an instance of MyClass like this:

```
MyInterface myClass = new MyClass();

```

The compiler wouldn't let me access its instance method without an explicit casting:

```
myClass.foo();  // Can't resolve symbol
((MyClass) myClass).foo(); // this is okay

```

Even though the compiler obviously knows myClass is an instance of MyClass:

```
if(myClass instanceof MyClass)
  System.out.println(myClass.getClass().getName()); //this will print "MyClass"

```

Why do i need to use cast for compiler to allow me to access the instance method?

Answer: 
The *meaning* of the line `MyInterface myClass = new MyClass()` is, "Create a new `MyClass`, and then forget about all its features except those defined in the interface `MyInterface`."

When you refer to "the compiler obviously knows myClass is an instance of MyClass," you're not actually correct: it's *not* the compiler that knows that, but the *runtime.* The *compiler* was told to forget that information, and it did.
It might be of type `MyClass` but you are treating it as a `MyInterface`. When you do `A myVar = new B();` you only have access to whatever you can access in `A` even though `myVar`is of type `B`.