Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Aditi Msc   on May 19 In Java Category.

  
Question Answered By: Omar Walker   on May 19

what ever the way u used for casting is correct way and for ur required
output you can change the derived  class as follows:
class Derived extends Base
{
public String toString()
{
return ("i = " + i);
}
}
also instead of using these 3 steps for casting
Derived d = new Derived();
Base b ;
b = (Base)(d);
you can do it in a single step like
Base b=new Derived();
thats it over.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How do we cast a Derived class to Base class Or get search suggestion and latest updates.


Tagged: