what are upcasting and downcasting?

Answer Posted / vikram aditya

When reference variable of super class refers to the object of sub class that mechanism is known as Up-casting.
Ex:
A a=new B();

When reference variable of sub class refers to the object of super class that mechanism is known as Down-casting.
Ex:
B b=(B) a;

//Where A is super class and B is subclass
 

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by formatting?

544


How to restrict a member of a class from inheriting by its sub classes?

795


What is __ init __ functions?

542


Is there any case when finally will not be executed?

521


What is break and continue statement?

611






Explain working of call by reference function invoking.

585


What is oop in java?

522


Is space a string in java?

508


Is intellij better than eclipse?

538


What are the object and class classes used for?

552


Can you override a final method?

578


How java uses the string and stringbuffer classes?

513


Is java still relevant?

495


What is the method in java?

593


Can we have try block without catch block?

580