Sunday, May 20, 2018

What is Object oriented programming:

Father - Son, go and get Red Label
Son - 750ml or 1 ltr??

Mother - Son, go and get Red Label
Son - 500gms or 1 kg??!!

Wednesday, May 9, 2018

My student achieved a certificate

Its great  news for me, when I knew that Er. Mayank Kumar has worked on java project for ZipUnzip software, and achieved this certificate from Vinoba Behave University, Hazaribag.

He is one of my best student and I wish him a bright future.

Why downcasting in java is dangerous

By casting we don't cast the real object, but just labelled it in different ways. Cat can be upcast to Animal, but the real object always remains cat, however we labelled it as Animal, however if need to get the properties of cat, we have to downcast from Animal to Cat.

But, if we will try to downcast in inappropriate class type which is not actually referred by the reference variable, then it gives an exception.

For example:

If superclass reference holds the object of subclass then it's okay to type cast, but just imagine if it doesn't…

class A{}

class B extends A{}

A a = new B()

B b = (B)a; // no problem

A a1 = new A();

B b1 = (B)a1; // type cast causes error