• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

downcasting

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tank UUUUUUUUUU
 
reply
    Bookmark Topic Watch Topic
  • New Topic