• Post Reply Bookmark Topic Watch Topic
  • New Topic

downcasting  RSS feed

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to downcast a abstract class A to derived class D?

e.g:

abstract class A{
}
class derived {
derived d=new derived();
A a=new A();
d=(derived) a;
}
 
Vijay Kiran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot instantiate object of abstract class using "new A();". If you want to have the abstract type from the derived you can directly use:

AbstractClass ab = new Derived();
 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to downcast a abstract class A to derived class D?

e.g:

abstract class A{
}
class derived {
derived d=new derived();

d=(derived) a;
}
how to convert a abstract class to a base class,is it possible?
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amit bhadre:
How to downcast a abstract class A to derived class D?

e.g:

abstract class A{
}
class derived {
derived d=new derived();

d=(derived) a;
}
how to convert a abstract class to a base class,is it possible?


For starters, you're going to have to learn a little bit of syntax:
For beginners, it helps to have a good book, like Head First Java, and to read some tutorials: http://java.sun.com/docs/books/tutorial/index.html
 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tank UUUUUUUUUU
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!