Down Casting a Enumeration

I tried the following code snippet.
import java.util.*;
class Strings implements Enumeration {
public boolean hasMoreElements() { return false;}
public Object nextElement() {return null;}
public class MainClass
public static void main(String args[])
Vector VectorObj = new Vector();
VectorObj.add("One");
VectorObj.add("Two");
VectorObj.add("Three");
Strings StringObj = (Strings) VectorObj.elements();
It compiles properly but i get the following run time exception:
java.lang.ClassCastException: java.util.Vector$1
what could be the problem? Do i need to do anything extra for the downcast?
TIA,
Babu

Had a look into the implementation of Vector.elements(). The inner class in elements() was causing the problem.
public Enumeration elements() {
return new Enumeration() {
int count = 0;
public boolean hasMoreElements() {
return count < elementCount;
public Object nextElement() {
synchronized (Vector.this) {
if (count < elementCount) {
return elementData[count++];
throw new NoSuchElementException("Vector Enumeration");
Thanks,
Babu

Similar Messages

  • Inhiterance:unknow down-cast exception.Access a private attrib.from subclas

    Hi guys,
    I need your help.
    Many examples, shows that i can create a sub-class inheriting from a super-class, add methods and attributes, make something like : <subclass variable> ?= <superclass instance> and then call method of the subclass (that are able to access to protect data of superclass instance for example).
    But when i try to do the same with a class derived from cl_gui_alv_grid, i have always a casting type exception in the down-cast instruction.
    Example :
    field-symbols: <outtab> type standard table.
    data : gos_alv type ref to cl_gui_alv_grid.
    *       CLASS lcl_gui_alv_grid DEFINITION
    class lcl_gui_alv_grid definition inheriting from cl_gui_alv_grid.
      public section.
        methods : get_tab_line.
    endclass.                    "lcl_gui_alv_grid DEFINITION
    *       CLASS lcl_gui_alv_grid IMPLEMENTATION
    class lcl_gui_alv_grid implementation.
      method get_tab_line.
    * mt_outtab is the data table held as a protected attribute
    * in class cl_gui_alv_grid.
        assign me->mt_outtab->* to <outtab>. "Original data
      endmethod.                    "get_tab_line
    endclass.                    "lcl_gui_alv_grid IMPLEMENTATION
    data : l_alv type ref to lcl_gui_alv_grid.
    But when i do a downcast like this (gos_alv was already created with "create object" istruction):
    l_alv ?= gos_alv.
    I have an exception of casting error. I cannot understand why and how to solve the problem.
    Thank you very much for your collaboration.
    Andrea

    Hi Andrea,
    I suggest you to tweak a code a litte bit as I guess the point is to get mt_outtab table, right?
    CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
      PUBLIC SECTION.
        CLASS-METHODS get_tab_line IMPORTING o_alv TYPE REF TO cl_gui_alv_grid.    "declare method as static one
    ENDCLASS.                   
    CLASS lcl_gui_alv_grid IMPLEMENTATION.
      METHOD get_tab_line.
        FIELD-SYMBOLS <outtab> TYPE STANDARD TABLE.
        assign me->mt_outtab->* to <outtab>.
        "your desired coding here
      ENDMETHOD.                   
    ENDCLASS.                   
    Now all you need to do is to call static method get_tab_line providing your actual alv reference
    data : gos_alv type ref to cl_gui_alv_grid.
    CREATE OBJECT gos_alv ....
    lcl_gui_alv_grid=>get_tab_line( gos_alv ).     
    As for your question, why this code
    l_alv ?= gos_alv.
    triggeres an exception cx_sy_move_cast_error .
    If you use this coding
      TRY.
          l_alv ?= gos_alv.
        CATCH.
          cx_sy_move_cast_error
    "system will end up here
      ENDTRY.
    ...you would prevent the system to dump out, but the exception will be triggered anyway. You will just catch it.
    The problem arises simply from fact that down cast checks wheterer these two reference variables l_alv and gos_alv are on the same level. This is why you put there question mark ? asking the system if gos_alv in fact contains appropriate reference. You can only evaluate it during program execution.
    When it comes to down cast always image such situation.
    You have VEHICLE class (your cl_gui_alv_grid ). The class which inherits from it is PLANE (your lcl_gui_alv_grid). Now you can always do such assingnment
    VEHICLE = PLANE (cl_gui_alv_grid = lcl_gui_alv_grid)    "up cast - narrow cast
    but you never can do this
    PLANE = VEHICLE (lcl_gui_alv_grid = cl_gui_alv_grid)  "down cast
    It is becasue plane is always a vehicle, but vehicle doesn't have to be a plain. It can be either a truck, ship or a plane.
    Therefore for down cast you always has to ask system if VEHICLE really contains (during exection) reference to a PLANE. That's why you write it like
    PLANE ?= VEHICLE (lcl_gui_alv_grid ?= cl_gui_alv_grid)
    The system checks then if vehicle really contains plane reference inside.
    Thought it might be not useful for first sight, it is a basis of polimorphism, but it is a talk for another time;)
    Regards
    Marcin

  • Is down casting possible in Java objects(reference variables)?

    I hope, Java up casting and down casting is possible in Java primitive variables like int float and so on.
    My doubt is,Does in object of Java(reference variables) support down casting?

    makpandian wrote:
    the ques i asked here is popped from my mind.We know that.
    But i did not get answer .Because you didn't do any research.
    Than s why i ask this here..That's the wrong approach. Do some research first. Use google, a textbook, a tutorial, the JLS, write some code, etc. etc.
    After spending time and effort doing that, if you still have questions, indicate clearly what you read and what part you didn't understand. The way you're doing it is NOT an effective way to learn, and it's a waste of everyone's time.

  • ABAP Object (Up cast, Down Cast)

    Someone should let me know.
    Version 4.70 Enterprise was as follows.
    " Up Cast (Narrowing-Cast)
      superclass = subclass.
    " Down Cast (Widening-Cast)
      subclass ?= superclass.
    It is why the help of F1 is changed as follows from the version ECC 6.0.
    (Widening-Cast and Narrowing-Cast became reverse.)
    " Up Cast (Widening-Cast)
      superclass = subclass.
    " Down Cast (Narrowing-Cast)
      subclass ?= superclass.

    Hello Tayori,
    You are referring to the link: [ABAP Objects: Narrowing Cast (Upcasting) |http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html], than you must have read the discussion between me and Christian.
    I am not clear why SAP has changed the definition.
    I am on ECC 5.0 and in my F1 defintion it says Narrowing Cast = Upcasting.
    It is better not to use Upcasting or Downcasting terms, as they are with the reference of the your view of Inheritence Tree. So, we can stick to the standard terms like Narrowing and Widening Cast.
    Narrowing:  "More Specific view of an object" to "less specific view".
    Like: BMW to CAR
    Widening: "Less Specific View of an ojbect" to "More Specific view"
    Like: CAR to BMW
    Regards,
    Naimesh Patel

  • Cast error in java sound

    Hey, i got a little run-time error:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.sun.media.sound.PortMixer$PortMixerPort
    the code segment it occurs at is here:
    case 0:
          targetDataLine1 = (TargetDataLine)mixer1.getLine(targetInfo);
          targetDataLine2 = targetDataLine1;
    }Some background info: I used getTargetLines() method of Mixer to obtain an arraylist of all the Line.Info objects (for targetLines) in a mixer, then I passed this into a GUI class, and made a vector to display in combo box. once user selects an item, it casts it back into Line.Info, and calls the mixer's "getLine()" method to retrieve the line. But I get the cast error. I know you can cast from Line to TargetDataLine (since TargetDataLine is a subinterface of Line) -- and I saw it on a tutorial, so I don't know what's wrong. Any help?
    If you need more info, just tell me.

    But still, the tutorial I looked at
    (http://java.sun.com/j2se/1.5.0/docs/guide/sound/progr
    ammer_guide/chapter3.html#113154)
    still showed it down-casting from a Line object to a
    TargetDataLine object.
    You need to understand the difference between a reference and an object. The object itself was a TargetDataLine object, otherwise the cast wouldn't have worked. The reference to it was of type Line.
    // obj is a reference of type Object. The object it points to is a String:
    Object obj = "I am a String";
    // Which explains why this works:
    String s = (String)obj;
    // and why this fails:
    Integer i = (Integer)obj;
    Not to mention, the java API says that the
    getLine(Line.Info) object returns an object of type
    Line.
    And I still don't understand why you can't cast from
    a superclass to a subclass. I know intuitively, it
    makes since, since not all RECTANGLES are SQAURES,
    but all SQUARES are RECTANGLES. But still, I know
    enough programming to remember numerous instances of
    casting Object as other classes....
    See above.
    Oh, and what does the $ symbol in
    com.sun.media.sound.PortMixer$PortMixerPort mean?It means that the the class PortMixerPort is an inner class (or nested class, I never remember the difference :-) in the class PortMixer.

  • Doubts on casting concepts in TAW12 part 1

    Can someone help me clarify a little confusion on Casting in materials provided by SAP Education on TAW12 part 1.
    I attended ILT and my instructor emphasized that: "wherever in this material we read 'Up-cast' or 'Down-cast', we should consider this as an error because what they meant to say is exactly the opposite".
    This has now left me confused especially after revising.
    Can someone please share some light on these terminologies and concept? especially in relation to materials provided on TAW12 ABAP Workbench Concept Part 1 (2013 SAP AG. All rights reserved)
    I have not been able to find much materials online for this section of the book and for many others.
    Any help would be greatly appreciated.
    Vince

    Hi Vince,
                   First thing, STOP worrying about the SAP material whether the contain is right/wrong.
                  Now, what I understand is that the instructor tried to explain the concepts in a easy way to remember but has that seems to have messed up your basics on up-cast & down-cast.
    I have looked in my sap material ( but its 2005 SAP AG reserved ).  The definition are fine.
    Anyways I'll try to explain in my style:
    Narrow casting( up-casting ):- Assigning of a subclass instance to a reference variable of type " reference to super class ". Here we navigate from a more detailed view to one with less details.
    Widening Cast( down-cast ):-  Assigning a super class to a sub class. From a less detailed view to more detailed view.
                             SUPER CLASS( vehicle ) less details
                                       |
                                       |
                                       |
                                SUB CLASS ( car, truck, bus, bike ) more details
    PS:- Try to understand the meaning from the example and then go back to the definition in the material.

  • 关于 narrowing cast 的疑问...

    请教大家一个问题。
    在 ABAP Keyword Documentation 中对 MOVE 的说明中有这样一段话:
    Both these statements assign the content of the operand source to the data object destination. The variants with the addition TO or the assignment operator = are valid for all assignments between operands that are not reference variables, and for assignments between reference variables for which the static type of source is more specific than or the same as the static type of destination (narrowing cast).
    但是在 ABAP Glossay 中对narrowing cast的说明是:Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast.
    这两段对于narrowing cast的描述是相反的,哪个是正确的?谢谢!

    谢谢您的回复。但是不好意思,我还是没有明白。
    正如您所说的:
    第一段说的是操作符 = 或者语法MOVE...TO...的概念,第二段说的是 ?= 或MOVE...?TO..
    但是到底哪个是narrowing cast?
    第一段说 ...(narrowing cast)。=> 它是narrowing cast
    第二段说 Also called a narrowing cast, a down cast ... => 它也是 narrowing cast,又称 down cast
    您说 不满足以上任何一个Narrowing Casting条件的,要使用Widening Casting(Down Casting)  => narrowing cast 和 down cast 是相反的

  • Change Narrowing and Widening Cast

    I have ABAP Object 2007 book from Horst Keller and I also have a 7.0 SAP System.
    SAP have changed the terminology from SAP 6.40.
    Please see this hyperlink  [Version 7.0 ABAP Modification 6|http://help.sap.com/abapdocu/en/ABENNEWS-70-DOCU.htm#!ABAP_MODIFICATION_6@6@]
    In addition when I click on Help on MOVE and the Casting operator in my 7.0 Version system is explained as
    Up Cast
    Also referred to as widening cast. Assignment between reference variables, where the static type of the target variables is similar or identical to the static type of the source variables.
    Down cast
    Also called a narrowing cast, a down cast is an assignment between reference variables in which the typr static type of the target variable more specific than the static type of the source variable. A down cast is only possible in assignments with the casting operator (?=) or MOVE ... ?TO. Compare with up cast
    SAP now want you to use the unambiguous terms of UP and DOWN  Version 7.0 of course.
    Does anybody have a pre640 SAP system (46C,47) that can confirm that the terminology has changed ?

    Hi,
    The terminology has not changed, but its a prior mistake made while writing notes, but the concept still remains the same as far as I have check in systems...
    Regards,
    Siddarth

  • Upcasting and narrow casting in oo-abap

    hi friends,
    please tell me clearly about the Up casting and Down casting with examples in OO-ABAP.
    thanks and regards.
    Moderator message : Search for available information, read forum rules before posting. Thread locked.
    Edited by: Vinod Kumar on Nov 9, 2011 5:32 PM

    Hi,
         Instance components exist separately in each instance (object) of the class and are referred using instance component selector using u2018u2019.
         Static components can be used without even creating an instance of the class and are referred to using static component selector     u2018 =>u2019 .
    CLASS c1 DEFINITION.
    PUBLIC SECTION.
      data : i_num type i value 5.
      class-data :   
        s_num type i value 6 .
    ENDCLASS.
    CLASS c1 IMPLEMENTATION.
    ENDCLASS.
    START-OF-SELECTION.
    DATA : oref1 TYPE REF TO c1 .
    CREATE OBJECT : oref1.
    write:/5 oref1->i_num.
    write:/5 c1=>s_num .
    write:/5 oref1->s_num.
                             Instance, self-referenced, and static methods can all be called dynamically; the class name for static methods can also be determined dynamically:
    u2022     oref->(method)
    u2022     me->(method)
    u2022     class=>(method)
    u2022     (class)=>method
    u2022     (class)=>(method)

  • Usage of widening cast in abap oops

    hi experts,
    I understood the widening cast concept. i want to know in what scenarios, the usage of widening cast makes sense. does the widening improve performance of the program? is there any scenario where we MUST use the widening cast in the logic? i want to understand how do we justify the usage of widening cast.
    please do not give me links explaining widening case. I know what widening cast is, but want to understand the need for it and how it helps in programing.
    thanks

    As for the thread's question: you use it when you have a subclass instance being pointed at by a superclass reference, and you need to access subclass specific components.
    Adding about widening / down cast:
    I repeat: you don't have choice.
    You actually do. Check the following example. BAPIRET2_T is a table type for BAPIRET2.
    You can call the method YOU know the actual referenced object of a subclass supports dynamically, like this:
    * Using downcasting
    DATA lo_tabledescr TYPE REF TO cl_abap_tabledescr.
    DATA lo_structdescr TYPE REF TO cl_abap_structdescr.
    DATA lv_linetypename  TYPE string.
    TRY.
        lo_tabledescr   ?= cl_abap_typedescr=>describe_by_name( 'BAPIRET2_T' ).
        lo_structdescr  ?= lo_tabledescr->get_table_line_type( ).
      CATCH cx_sy_move_cast_error.
        MESSAGE 'Error in downcast!' TYPE 'A'.
    ENDTRY.
    lv_linetypename = lo_structdescr->get_relative_name( ).
    WRITE: /, lv_linetypename.
    * Alternative way using dynamic calling
    DATA lo_typedescr_tab TYPE REF TO cl_abap_typedescr.
    DATA lo_typedescr_str TYPE REF TO cl_abap_typedescr.
    lo_typedescr_tab   = cl_abap_typedescr=>describe_by_name( 'BAPIRET2_T' ).
    TRY.
        CALL METHOD lo_typedescr_tab->('GET_TABLE_LINE_TYPE')
          RECEIVING
            p_descr_ref = lo_typedescr_str.
      CATCH cx_sy_dyn_call_error.
        MESSAGE 'Error in dynamic call!' TYPE 'A'.
    ENDTRY.
    lv_linetypename = lo_typedescr_str->get_relative_name( ).
    WRITE: /, lv_linetypename, '...again'.
    Note that in either approach, you should catch the relevant exception(s) that may occur, unless you are certain about the object's actual subclass.
    Edited by: Alejandro Bindi on Mar 31, 2010 5:47 PM
    As you can see I got confused by the narrowing / widening terms as well. I also found out the terms upcast / downcast to be much easier to understand.

  • Regarding Narrow casting

    Hi Experts,
    Here i am giving one program about narrow casting in which i am not able to access the method called 'fasting', but here i am able to access dynamically.
    So, while doing narrow casting may i know that only dynamically we can able to access that method?
    and may i know the clear picture of wide castening & narrow castening with example.
    Please help it out.
    REPORT  Z15704_NARROWING.
    CLASS lcl_animal DEFINITION.
       PUBLIC SECTION.
         METHODS: hungry.
         ENDCLASS.
         CLASS lcl_lion DEFINITION INHERITING FROM lcl_animal.
            PUBLIC SECTION.
             METHODS: hungry REDEFINITION,
                     fasting.
             ENDCLASS.
             CLASS lcl_animal IMPLEMENTATION.
               METHOD hungry.
                   WRITE: / 'An animal is hungry'.
                    ENDMETHOD.
                    endclass.
                      "hungryENDCLASS.
    CLASS lcl_lion IMPLEMENTATION.
      METHOD hungry .
         WRITE: / 'A Lion (King of Jungle) is hungry.'.
          ENDMETHOD.                    "hungry  METHOD fasting.
          METHOD fasting.
           WRITE: / 'Stop running. Lion is on Fasting today.'.
           ENDMETHOD.
           ENDCLASS.
           START-OF-SELECTION.
            DATA: lo_animal TYPE REF TO lcl_animal,
                      lo_lion   TYPE REF TO lcl_lion.
           " ** ANIMAL object without NARROW casting
            WRITE: / 'Animal - without NARROW casting'.
             CREATE OBJECT lo_animal.
               CALL METHOD lo_animal->hungry( ).
              CLEAR lo_animal.
              "** ANIMAL object with NARROW CASTING  SKIP 2.
               WRITE: / 'Animal -  NARROW casting from LION'.
               CREATE OBJECT lo_lion.
                lo_animal = lo_lion.
                CALL METHOD lo_animal->hungry( ).
                CALL METHOD lo_animal->fasting( ).
    when i call  this method dynamically CALL METHOD lo_animal->('fasting'). i am able to access.
    Thanks,
    Radhika

    In Narrow casting, we create a object reference to the Subclass (LO_LION) first and than we assign that object reference to the reference of the Superclass (LO_ANIMAL). Here we have moved from more specific object to less specific object.
    Refer: http://help-abap.blogspot.com/2008/09/abap-objects-narrowing-cast-upcasting.html
    In widening cast, we create a object referece to the superclass (LO_ANIMAL)  first and than we assign the object reference to the Subclass (LO_LION). Here we move from General object to Specific object. As the principal of the inheritance, every Subobject (LO_LION) will have more attributes/properties than the General object (LO_ANIMAL). So, it would not be possilbe to just create LO_ANIMAL and move to LO_LION. So, when we do the Widening cast, we need to first use the narrow casting somewhere in the program to assign proper proerties of subobject (LO_LION) to Superobject (LO_ANIMAL). Than you will successfully move that reference back to Superobject (LO_ANIMAL) to different subobject (LO_LION2).
    Refer: http://help-abap.blogspot.com/2008/09/abap-objects-widening-cast-down-casting.html
    Regards,
    Naimesh Patel

  • Narrow Casting

    Hi all,
    Can anybody please tell the usuage of narrow casting.
    preferable with simple code.
    Anirban Bhattacharjee

    Hi,
    Narrowing Cast
    If the static type of the target variable is less specific or the same as the static type of the source variable, assignment is always possible. In comparison to the source variable, the target variable knows the same or fewer attributes of the dynamic type. As a result, this assignment is referred to as narrowing cast. A narrowing cast is possible in all ABAP statements in which the content of a data object is assigned to another data object. These include, for example, assignments with the normal assignment operator (=), the insertion of rows in internal tables, or the transfer from actual to formal parameters.
    This means a ref object used is of a child. Now here technically speaking you can call all the methods of the parent class as well as of the child class. So in this case, at runtime if the child object point to a prent object then it will cause an issue if a method specific to a child is called.For the compiler it is not possible to detect this at compile time, like in the above case and therefore a runtime exception is possible.
    Variables of the type reference to superclass can also refer to subclass instances
    at runtime. You may now want to copy such a reference (back) to a suitable
    variable of the type reference to subclass.
    If you want to assign a superclass reference to a subclass reference, you must
    use the down-cast assignment operator MOVE ... ?TO ... or its short form
    ?=. Otherwise, you would get a message stating that it is not certain that all
    components that can be accessed syntactically after the cast assignment are
    actually available in the instance. As a rule, the subclass class contains more
    components than the superclass.
    After assigning this type of reference (back) to a subclass reference to the
    implementing class, clients are no longer limited to inherited components: In the
    example given here, all components of the LCL_TRUCK instance can be accessed
    (again) after the assignment using the reference R_TRUCK2.
    The view is thus usually widened (or at least unchanged). That is why we describe
    this type of assignment of reference variables as down-cast. There is a switch
    from a view of a few components to a view of more components. As the target
    variable can accept less dynamic types after the assignment, this assignment is
    also called Narrowing Cast
    Reward points if useful.
    Best Regards,
    Sekhar

  • " casting in java "

    Hi All,
    Can some one help me find out whats the error in my code??
    what/where is wrong in my casting??
    import java.lang.* ;
    class base {
    public void display()
    System.out.println( " i am in base ");
    class derv extends base{
    public void show()
    System.out.println( " i am in derv ");
    class test13 {
    public static void main(String args[]) throws ClassCastException {
    base Obj1 = new base();
    base Obj2 = new derv();
    derv Obj3 = new derv();
    //derv Obj4 = new base();//not valid
    Obj1.display();// regular
    Obj2.display();
    Obj3.display();
    Obj3.show();// regular
    derv Obj4 = new derv();
    Obj4 = (derv) Obj1;
    Obj4.show();
    derv Obj5 = new derv();
    Obj5 = (derv) Obj2;
    Obj5.show();
    };i am getting a run time exception like this :
    C:\JAVAEX~1\test>java test13
    i am in base
    i am in base
    i am in base
    i am in derv
    Exception in thread "main" java.lang.ClassCastException: base
    at test13.main(test13.java:37)
    Thank you very much in advance..
    Thanks and regards,

    The cast cast occured because you tried an downcast.
    may be this could help
    public class A1{
         A1(){
              A1 a=new A1();
              B1 b=new B1();
              //up cast...
              A1 a1=b;// no need of explisit cast
              //down cast          
               /*explisit cast requires..may throw exception, if a is not an instance of B1..
              ie. it will thorow excpetion in this case*/
              B1 b1=(B1)a;
              //example of not throwing excpetion..
              B1 b2=(B1)a1;
    class B1 extends A1{

  • Casting

    What is the concept of casting in ABAP?
    what is the difference between UP CAST & DOWN CAST?
    regards,
    Sharayu

    Go to ABAPDOCU tcode and see example programs in abap objects section, you will find separate programs for upcasting and downcasting .
    Up-Cast (Widening Cast)
    Variables of the type reference to superclass can also refer to subclass instances at runtime.
    If you assign a subclass reference to a superclass reference, this ensures that
    all components that can be accessed syntactically after the cast assignment are
    actually available in the instance. The subclass always contains at least the same
    components as the superclass. After all, the name and the signature of redefined
    methods are identical.
    The user can therefore address the subclass instance in the same way as the
    superclass instance. However, he/she is restricted to using only the inherited
    components.
    In this example, after the assignment, the methods GET_MAKE, GET_COUNT,
    DISPLAY_ATTRIBUTES, SET_ATTRIBUTES and ESTIMATE_FUEL of the
    instance LCL_TRUCK can only be accessed using the reference R_VEHICLE.
    If there are any restrictions regarding visibility, they are left unchanged. It is not
    possible to access the specific components from the class LCL_TRUCK of the
    instance (GET_CARGO in the above example) using the reference R_VEHICLE.
    The view is thus usually narrowed (or at least unchanged). That is why we
    describe this type of assignment of reference variables as up-cast. There is a
    switch from a view of several components to a view of a few components. As
    the target variable can accept more dynamic types in comparison to the source
    variable, this assignment is also called Widening Cast
    Static and Dynamic Types of References
    A reference variable always has two types at runtime: static and dynamic.
    In the example, LCL_VEHICLE is the static type of the variable R_VEHICLE.
    Depending on the cast assignment, the dynamic type is either LCL_BUS or
    LCL_TRUCK. In the ABAP Debugger, the dynamic type is specified in the form
    of the following object display.
    Down-cast (Narrowing Cast)
    Variables of the type “reference to superclass” can also refer to subclass instances
    at runtime. You may now want to copy such a reference (back) to a suitable
    variable of the type “reference to subclass”.
    If you want to assign a superclass reference to a subclass reference, you must
    use the down-cast assignment operator MOVE ... ?TO ... or its short form
    ?=. Otherwise, you would get a message stating that it is not certain that all
    components that can be accessed syntactically after the cast assignment are
    actually available in the instance. As a rule, the subclass class contains more
    components than the superclass.
    After assigning this type of reference (back) to a subclass reference to the
    implementing class, clients are no longer limited to inherited components: In the
    example given here, all components of the LCL_TRUCK instance can be accessed
    (again) after the assignment using the reference R_TRUCK2.
    The view is thus usually widened (or at least unchanged). That is why we describe
    this type of assignment of reference variables as down-cast. There is a switch
    from a view of a few components to a view of more components. As the target
    variable can accept less dynamic types after the assignment, this assignment is
    also called Narrowing Cast
    Keep fighting and win the race.

  • Type casting in OOPS ABAP

    Hi Team,
                 Could any one explain me about Type casting used in oops abap and in what circumstances it is
    used with an example.
    Regards,
    Pradeep P.

    Hi,
    Hi,
    Go to ABAPDOCU tcode and see example programs in abap objects section, you will find separate programs for upcasting and downcasting .
    Up-Cast (Widening Cast)
    Variables of the type reference to superclass can also refer to subclass instances at runtime.
    If you assign a subclass reference to a superclass reference, this ensures that
    all components that can be accessed syntactically after the cast assignment are
    actually available in the instance. The subclass always contains at least the same
    components as the superclass. After all, the name and the signature of redefined
    methods are identical.
    The user can therefore address the subclass instance in the same way as the
    superclass instance. However, he/she is restricted to using only the inherited
    components.
    In this example, after the assignment, the methods GET_MAKE, GET_COUNT,
    DISPLAY_ATTRIBUTES, SET_ATTRIBUTES and ESTIMATE_FUEL of the
    instance LCL_TRUCK can only be accessed using the reference R_VEHICLE.
    If there are any restrictions regarding visibility, they are left unchanged. It is not
    possible to access the specific components from the class LCL_TRUCK of the
    instance (GET_CARGO in the above example) using the reference R_VEHICLE.
    The view is thus usually narrowed (or at least unchanged). That is why we
    describe this type of assignment of reference variables as up-cast. There is a
    switch from a view of several components to a view of a few components. As
    the target variable can accept more dynamic types in comparison to the source
    variable, this assignment is also called Widening Cast
    Static and Dynamic Types of References
    A reference variable always has two types at runtime: static and dynamic.
    In the example, LCL_VEHICLE is the static type of the variable R_VEHICLE.
    Depending on the cast assignment, the dynamic type is either LCL_BUS or
    LCL_TRUCK. In the ABAP Debugger, the dynamic type is specified in the form
    of the following object display.
    Down-cast (Narrowing Cast)
    Variables of the type “reference to superclass” can also refer to subclass instances
    at runtime. You may now want to copy such a reference (back) to a suitable
    variable of the type “reference to subclass”.
    If you want to assign a superclass reference to a subclass reference, you must
    use the down-cast assignment operator MOVE ... ?TO ... or its short form
    ?=. Otherwise, you would get a message stating that it is not certain that all
    components that can be accessed syntactically after the cast assignment are
    actually available in the instance. As a rule, the subclass class contains more
    components than the superclass.
    After assigning this type of reference (back) to a subclass reference to the
    implementing class, clients are no longer limited to inherited components: In the
    example given here, all components of the LCL_TRUCK instance can be accessed
    (again) after the assignment using the reference R_TRUCK2.
    The view is thus usually widened (or at least unchanged). That is why we describe
    this type of assignment of reference variables as down-cast. There is a switch
    from a view of a few components to a view of more components. As the target
    variable can accept less dynamic types after the assignment, this assignment is
    also called Narrowing Cast
    Reward if helpfull,
    Naresh.

Maybe you are looking for

  • Upgraded to 7.0.1 Problems with music quality

    I've upgraded to 7.0.1 & my music quality for both imported CD tracks & iTunes downloaded music is now jittery with delays and skips, the quality was fine with previous release,any help would be appreciated iPod 60gb   Windows XP Pro  

  • Because The Light Of My Macbook Screen Went Out

    Hello everyone. I have a normal macbook with 2GB of ram. dual core processor.2.4 the macbook is 13 inches. Well the fact is that I have a 30 gb ipod! I'm lovingthe apple. and I have restored and installed with the disk utilities mac osx leopard.in th

  • Standalone windows services as opposed to Domain Member

    Hi I know very little about windows networking, and have a basic question. I have a school network with mostly macs, and a 10.4 server. There is also a windows server on the network that someone else comes in to maintain that supplies all the windows

  • CC Desktop login

    CC desktop is installed but when I try to log in it responds only that I have been logged out

  • Arch update error .

    new install arch pacman -Syyu , error, xxx file exist, must : pacman -S filesystem --force Everyone have any other ways to solve it ?? We have to continue endure this? Last edited by leic (2012-03-02 14:15:32)