• 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

creating objecct

 
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PLEASE PROVIDE REASON ABOUT THE ERROR

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error? And please KeepItDown
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

changu mani wrote:During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;



The first line is legal. The second will give ClassCastException at runtime.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

changu mani wrote:During compile time, compiler is not aware of what kind of object ob is pointing to. So it is necessary to do external casting.
Do this way, the compiler error goes away.

Sub ob1= (Sub)ob;
Abc ob2=(Abc)ob;



Looks like you read: public class Sub extends Abc
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic