Doubt in interface reference

Select two correct statements about the code given below?
class A{}
class B extends A implements E{} //line 1
class C extends A{}
class D extends B{}
interface E{}
class Question07 {
public static void main(String[] args) {
A a = new D(); //line 2
C c = new C(); //line 3
E e = (E)a; //line 4
B b = e; //line 5
}Options
a. The code compiles without error and runs fine
b. Compilation error on line 1 because interface E is not yet declared (forward-referencing)
c. Compilation error on line 4 because class A does not implement interface E
d. The cast on line 4 is mandatory
e. The cast on line 5 is not mandatory
the answer is a,d,e three answers ! all answers understood except d option
how we can make E reference with casting A , and A is not implement E !!!
help me please
Message was edited by:
eaaje
Message was edited by:
eaaje

The type of variable a is A. Since A does not implement E, to assign a to a variable of type E you must cast it.

Similar Messages

  • Access to class-attribute by Interface-reference

    Hi OO-Gurus,
    I use an implementation of BADI ME_PROCESS_REQ_CUST to fill and handle user-defined fields in the MM-Purchase-Requisition, method IF_EX_ME_PROCESS_REQ_CUST~OPEN.
    There I  use a reference variable which refers to an interface (type ref to IF_PURCHASE_REQUISITION_ITEM) to access the item-object. My problem is that I need to have access to the class-attribute my_state. The corresponding class lcl_req_item is defined locally (LMEREQF01). So I can’t use  a reference variable with reference to this class (so widening cast using the interface-reference is not possible) .. Does anyone know a trick how to access the class-attribute anyway?
    Coding:
      data:  l_item_list       TYPE MMPUR_REQUISITION_ITEMS,
               l_item             TYPE MMPUR_REQUISITION_ITEM,
               l_item_akt       TYPE mereq_item,
               l_item_ref        TYPE ref to IF_PURCHASE_REQUISITION_ITEM. 
      l_item_list = im_header->get_items().
      loop at l_item_list into l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
      endloop.
    (Debugging the code, I manage by doubleclicking the fieldcontent of l_item_ref (e.g ) to show the content of the class-attribute my_state. This works only if the field “Interface” in the Debugger is empty because then I see the attributes of the class. If the field Interface is filled with “IF_PURCHASE_REQUISITION_ITEM”, there aren’t any attributes shown.)
    Thanks in advance for your kind help!!
    Nicole

    Hello Nicole
    The following sample coding shows you how to solve your problem. Please do not ask me how I came across this solution.
    However, if you are studying it carefully you may stumble across a most beautiful property of field-symbols as I did.
    METHOD if_ex_me_process_req_cust~open.
      DATA: l_item_list TYPE mmpur_requisition_items,
      l_item TYPE mmpur_requisition_item,
      l_item_akt TYPE mereq_item,
      l_item_ref TYPE REF TO if_purchase_requisition_item.
      DATA:
        ld_attr         TYPE string,
        lo_obj          TYPE REF TO object.
      FIELD-SYMBOLS:
        <lo_lcl>        TYPE ANY,
        <ls_item>       TYPE mereq_item,
        <ls_itemx>      TYPE mereq_itemx.
      l_item_list = im_header->get_items( ).
      LOOP AT l_item_list INTO l_item.
        l_item_akt = l_item-item->get_data( ).
        l_item_ref = l_item-item.
        lo_obj     ?= l_item-item.  " casting to root object !!!!!
        ld_attr = 'MY_STATE'.
        ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
        ld_attr = 'MY_STATE->ITEM'.
        ASSIGN lo_obj->(ld_attr) TO <ls_item>.
    "    ASSIGN l_item_ref->(ld_attr) TO <ls_item>.  " does not work...
        ld_attr = 'MY_STATE->ITEMX'.
        ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.
      ENDLOOP.
      " NOTE: data definition of local class lcl_req_item_state (fg MEREQ)
    **    DATA:  item           TYPE mereq_item,
    **           itemx          TYPE mereq_itemx,
    **           header         TYPE REF TO lcl_req_header,
    **           ref_item       TYPE REF TO lcl_req_item,
    **           acct_container TYPE REF TO lcl_acct_container,
    **           source         TYPE REF TO cl_source_of_supply_mm,
    **           release_state  TYPE REF TO cl_release_state_mm,
    **           text_manager   TYPE REF TO lcl_text_manager,
    **           bom            TYPE REF TO lcl_bom,
    **           funds_mgt_active TYPE mmpur_bool VALUE mmpur_no,
    **           aktyp          TYPE aktyp,
    **           no_auth        TYPE mmpur_bool VALUE mmpur_no,
    **           release_op     type mmpur_bool value mmpur_no,
    **           persistent     TYPE mmpur_bool VALUE mmpur_no,
    **           checked        TYPE mmpur_bool VALUE mmpur_no,
    **           manual_configuration TYPE mmpur_bool,
    **           input_buffer_changed TYPE mmpur_bool VALUE mmpur_no,
    **           changed        TYPE mmpur_bool,
    **           broken_rules   TYPE lty_mask,
    **           referenced_rules TYPE lty_mask,
    **           chp_changes    TYPE mmchp_chp_list,
    **           dcm_manager    TYPE REF TO if_revision_manager_dcm,
    **           "DCM Retrofit
    **           rel_state_after_release TYPE REF TO cl_release_state_mm,
    **           "DCM Retrofit
    **           chdoc_container TYPE REF TO lcl_chdoc_container,
    **           "DCM Retrofit
    **           service_changed TYPE mmpur_bool,
    **           "DCM Retrofit
    **           determinants   TYPE lty_item_determinants.
    ENDMETHOD.
    Regards
      Uwe

  • I have doubts in interface

    Hi all,
    I have doubts in interface . You please help me.
    My question was
    i have two interface. and also i have only one method in both interfaces.these method are same name in both interface
    Now i implement these interfaces in my class it's work properly. it doesn't through exceptions.
    But i have changed the return type of methods,
    ie i put int for one
    and void for another one.
    it throws exceptions . duplicate method access.
    how to i solve this problem? did u catch my point?
    please help me Advance in thanks.

    i have two interface. and also i have only one
    y one method in both interfaces.these method are same
    name in both interface
    Now i implement these interfaces in my class it's
    work properly. it doesn't through exceptions.
    But i have changed the return type of methods,
    ie i put int for one
    and void for another one.
    it throws exceptions . duplicate method access.
    how to i solve this problem? did u catch my point?Yes I caught it. The solution: don't do it. Methods differ by name and argument type list. Return values are not looked at.
    Another solution: have the methods take different arguments. Or rename one of them.

  • 1000v Removed Interface Reference

    Cisco Support,
    We recently swapped out 1GB interfaces in our ESX server and replaced them w/10GB cards.  When we did that, the interface IDs presented to the 1000v changed.  References to the removed interfaces still appeared when the "show port-channel sum" command was issued.  I managed to delete all but one of the unused port-channels which referenced the stale interface names.  Unfortunately, one of the interfaces is associated w/a port-channel that is actually in use (see below) and I can't delete it.  Is there a way to get rid of this stale interface reference?  Granted it isn't doing anything, but it looks sloppy.  Since the port-channel IDs are generated automatically, I can't just shuffle stuff around (at least I don't know a way of doing so).
    Running version 4.2(1)SV1(4a).
    Thanks in advance.
    -Erik
    1000v# sho port-channel sum
    Flags:  D - Down        P - Up in port-channel (members)
            I - Individual  H - Hot-standby (LACP only)
            s - Suspended   r - Module-removed
            S - Switched    R - Routed
            U - Up (port-channel)
    Group Port-       Type     Protocol  Member Ports
          Channel
    7     Po7(SU)     Eth      LACP      Eth6/3(P)    Eth6/5(P)    
    8     Po8(SU)     Eth      LACP      Eth7/3(P)    Eth7/5(P)    
    9     Po9(SU)     Eth      LACP      Eth3/3(P)    Eth3/5(P)    Eth3/7(r)  <-------------------

    Hey Erik,
    It is CSCua93737: Port-channel has Ghost entries even after removing ports from N1K setup
    You can view the defect using this link 
    https://tools.cisco.com/bugsearch/bug/CSCua93737
    Workaround:
    1. Create a new port-profile and associate new uplink interface to it.
    2. Associate active ports to the new port-profile so that there is a new port-channel created with active uplink ports.
    3. Delete the old port-channel so that all the ghost interfaces would be removed along with it. If you wish to use the same port-profile for all uplink ports, then you can move the uplink ports to the old port-profile one by one so that a new port-channel will be created using the same old port-profile.
    The defect is resolved in SV2(1.1).
    Thanks,
    Joe

  • Clear my  doubt on Interface

    Hi,
    When a class implement an interface,the method of the class should thorugh the same exception or any of its subclass exception or any different exception,as that of the exception declared on the abstarct method of the interface.
    Please any one solve my doubt as early as possible.
    Thanks
    Vish

    Hi,
    When a class implement an interface,the method of
    the class should thorugh the same exception or any of
    its subclass exception or any different exception,as
    that of the exception declared on the abstarct method
    of the interface.
    Is this supposed to be multiple choice?
    The easiest way for you to answer this question is to try it out yourself in code.

  • Static verification of interface references

    The JVM spec (prior to JDK 6, to keep it simple) implies that static data-flow-based verification is done on methods at class load time, including the parameters to method calls. For object references (pointers) this, as I understand it, assures than the class flowing to a use of a reference either matches the use exactly or can be "widened" to match the use, based on the "widening reference conversions" described in the language spec.
    What I can't figure out is that this definition of "widening" does not appear to be applied to interfaces. Rather, "widening" of interfaces appears to be allowed (for static verification, not necessarily source compilation) somewhat blindly. Only if a method is called on an interface and the method is not implemented by the runtime object does an error appear to be generated.
    Is this true? If so, is the behavior documented anywhere?

    Here is an example of what I'm describing:
    package verify;
    public class Main
    public static void main(String args[]) {
         System.out.println("Hello");
         foo();
         System.out.println("Goodbye");
    public static void foo() {
         System.out.println("Entered Main.foo");
         B b = new rB();
         b.methodA();
    package verify;
    public interface A {
    public void methodA();
    package verify;
    public interface B
    // extends A
    public void methodB();
    package verify;
    public class rB implements B {
    public void methodA() {
         System.out.println("Inside B.methodA");
    public void methodB() {
         System.out.println("Inside B.methodB");
    The above is compiled initially with the commented lines included, then the lines are commented out and the two changed files are recompiled.
    ...> java -verify -Xverify -Xfuture verify.Main
    Hello
    Entered Main.foo
    Exception in thread "main" java.lang.IncompatibleClassChangeError: class verify.rB does not implement interface verify.A
         at verify.Main.foo(Main.java:12)
         at verify.Main.main(Main.java:6)
    As can be seen, the Main class loads successfully and the method foo is successfully invoked. No error is detected until the call to methodA is attempted.
    The "b.methodA();" statement is compiled as an invokeinterface on verify.A.methodA, but when Main is loaded and method foo invoked the variable b cannot be widened to an A. This is easily determined by static class flow analysis, and would most certainly result in a VerifyError if classes were involved rather than interfaces. Why is the class even allowed to begin execution?

  • CM Open Interface - reference back to original bank statement line

    we are using Open Interface for our bank reconciliation. we found that, the API APPS.CE_999_PKG.clear always send us the Open Interface Transaction amount as the cleared amount, and we have no visibility to the amount in the bank statement line.
    eg:
    bank statement line is $100
    if a user manually reconcile this line with an open interface transaction line with amount $200, the status will changed to reconciled and the cleared amount is $200.
    the cleared amount passed through the API to our customize program also $200.
    how can we get the amount $100?
    we are doing some GL posting for the cleared amount. getting $200 will caused us to do over post, as the amount we received only $100 (bank statement line amount)

    Hi All,
    I found this article, which explains about the bank statement mappings.
    *Mapping BAI2, SWIFT Bank Statement Format Masking: BANK_ACCOUNT_NUM, BANK_TRX_NUMBER, BANK_ACCOUNT_TEXT, Agent Bank account number And Others [ID 752532.1]*
    Based on this I defined a new bank statment mapping by coping the existing BAI2 mapping.
    The only change I had to do was to change the position of the BANK_TRX_NUMBER to -2 and my problem got resolved.
    Below is the question and answer as per the document.
    Q2: Why following BAI2 datafile needs bank statement mapping as:
    BANK_TRX_NUMBER 16 -2 and not -1?
    16,581,156500,Z,813009392186700,000000002004/
    A2:
    The bank statement mapping you give to populate depends on where the BANK_TRX_NUMBER is in the data file: Example:
    Rec 16 structure is as follows:
    16,<transaction code>,<amount>,<funds type>,<bank ref #>,<customer ref #>,<text>/
    In the rec:16,581,156500,Z,813009392186700,000000002004/
    while the NUMBER appears to be -1 position however the text is assumed missing here and hence the
    BANK_TRX_NUMBER 16 -2 will work.
    Thanks and Regards,
    MPH

  • Doubt about interfaces in "final Runnable closerRunner = new Runnable()"

    Till this date i think that interfaces can not be instantiated because they dont define methods.But one line of code found in a sample program(creating splash screen)creates lots of confusions to me.The line is as follows:
    final Runnable closerRunner = new Runnable()
    An interface is instantiated using "new" operator.How is this possible ?
    Any body help me please.
    The whole program follows:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class SplashWindow3 extends JWindow
    public SplashWindow3(String filename,JFrame f, int waitTime)
    super(f);
    JLabel l = new JLabel(new ImageIcon(filename));
    getContentPane().add(l, BorderLayout.CENTER);
    pack();
    Dimension screenSize =
    Toolkit.getDefaultToolkit().getScreenSize();
    Dimension labelSize = l.getPreferredSize();
    setLocation(screenSize.width/2 - (labelSize.width/2),
    screenSize.height/2 - (labelSize.height/2));
    addMouseListener(new MouseAdapter()
    public void mousePressed(MouseEvent e)
    setVisible(false);
    dispose();
    final int pause = waitTime;
    final Runnable closerRunner = new Runnable()
    public void run()
    setVisible(false);
    dispose();
    Runnable waitRunner = new Runnable()
    public void run()
    try
    Thread.sleep(pause);
    SwingUtilities.invokeAndWait(closerRunner);
    catch(Exception e)
    e.printStackTrace();
    // can catch InvocationTargetException
    // can catch InterruptedException
    setVisible(true);
    Thread splashThread = new Thread(waitRunner, "SplashThread");
    splashThread.start();
    public static void main(String [] a)
              //this.setSize(1000,1000);
              JFrame f=new JFrame();
              f.setSize(300,300);
              SplashWindow3 s=new SplashWindow3("shan.jpg",f,100000);
    }

    That is called an anonymous inner class.
    See JLS 15.9.
    http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.9

  • Hi sdn gems doubt on interface pls help

    my question is i have to do interface between ctts system to sap, in asingle program i have to upload two transactions MSC2 and MB1B with movement 311.
    can anyone pls help by sending code are suggestion.

    HI,
    You can do for any number of transactions.. one after the other...
       prepare BDC data for tcode 1
       call transaction 1.
       prepare bdc dta for tcode 1.
       call transaction 2.
      Thaks
    Mahesh

  • Doubts in interface

    If any data member of an interface ia automatically public, static and final then how we can shadow it in the class which is implementing the interface?
    interface iTest {
         public static final int i = 5;
         public void display();
    public class TEst implements iTest {
         int i = 10;
         public void display() {
              System.out.println(i);
         public static void main(String a[]) {
              TEst t = new TEst();
              t.display(); //prints 10 , why not 5?
    }Thanks for your reply.

    - Hiding Member Variables -
    Note: it is a good practice to refer to a static member by prefixing it with class name:     public static void main(String a[]) {
              TEst t = new TEst();
              t.display(); // prints 10
              System.out.println(iTest.i); // prints 5
         }

  • Doubt about interface & abstract

    Hai everybody,
    I am new java technology. I need clear discribtion about interface & abstract.
    Please give some examples and differentiate it.
    i awaiting for your reply
    by
    azhar

    Even Wikipedia has info about this:
    http://en.wikipedia.org/wiki/Interface_%28Java%29
    http://en.wikipedia.org/wiki/Class_%28computer_science
    %29#Abstract_and_concrete_classeswhenever someone asks this question, they don't really want to read about it, they just want someone to tell them the secret rules about when to use an interface and when to use an abstract class. but we're not telling :-)

  • Doubt on interface IFMD006.

    Hi Friends,
    I was asked to make changes to interface IFMD006.
    But i dont know where to find the interface.
    I have tried in SE24.. but it says the object does not exist..
    Is there any ways to find the Interface IFMD006.
    Please help me..
    Thanks,
    Gokul.

    Hi!
    If you mean a substitution for FI on this, then you gotta check out this link:
    Anyways, don't post everything 3 times!
    Anyways, don't post everything 3 times!
    Anyways, don't post everything 3 times!
    Regards
    Tamá

  • Doubt on Interface

    AnInterface ai = new AnInterfaceImpl();
    where AnInterface is an interface and AnInterfaceImpl is the class which implements AnInterface
    Does it make any sense do this?What is the purpose of a statement like this

    Means you can replace AnInterfaceImpl with some other class that implements AnInterface, without making any changes to code that uses 'ai'. JDBC is a good example of this in action.

  • Doubt in interface...

    interface I {
    int f(int x);
         int var = 4;
    public class C implements I {
    public int f(int x) {
    return x * x;
    public static void main(String[] args) {
         try
    I[] a = new C[I.var];
              System.out.println(a.length);
              System.out.println(a[0]);     //output - null
              System.out.println(a[1]);     //output - null
              System.out.println(a[2]);     //output - null
              System.out.println(a[3]);     //output - null
    for (int i=0; i<a.length; ++i)
    System.out.println(a.f(i));     // Null pointer exception
    }catch (Exception e){
              System.out.println("Error: "+e.getMessage());// error in this line
              e.printStackTrace();
         }//catch
    }//main
    }//class
    question: i have to call f() which is in interface a.length times. how?

    Multiple-post
    http://forum.java.sun.com/thread.jspa?threadID=5173053&tstart=0
    Original has formatting

  • E-Tester Script Programming Interface Reference Guide   - question

    Hello,
    I just came across this question posted as a Comment for this Knowledge Base document http://qazone.empirix.com/entry.jspa?externalID=34&categoryID=18, so I am adding it to the Forums for additional visibility and replies
    Author: Wegener, Posted: Jul 23, 2007 11:47 AM
    To get the current workspace in a Job Scheduler job I used the following code from the reference
    Private Sub ThisJob_JobBegin()
    Dim location
    location = application.currentResult.workspace
    End Sub
    As a result the value of the variable location changed from Empty to "".
    What can be the reason for this failure?

    We had a similar problem. You actually need to do this in job end or script end event. The application.currentResult object does not have any data until the end of a test.
    I hope this is helpful.

Maybe you are looking for

  • Problem with pages launching after update on Nov 23, 2013

    I haven't used pages until now.  I have update to Maverick (10.9); have update for pages from Nov. 23, 2013.  I tried to open it up but it will not open.  Has anyone had this problem. I have Keynote and it is not working, but have numbers and it is w

  • Problem using SAAJ with Applets

    This method to do a SOAP connection call does not work within a Applet -- but it works fine otherwise. Any help would be appreciated. Thanks. public void execute() {      try {          SOAPConnectionFactory           soapConnectionFactory     = SOAP

  • 10.4 Tiger Upgrade

    Hello, I'm getting ready to upgrade my iBook G4 from 10.3.9 to 10.4. Is there anything I need to do or any precautions I should be aware of before doing this? Will I lose any of my files? Will all my current applications still work? Does anyone know

  • Script for forward mail as attachment

    Hi, I think there is no direct call for creating forward mail as attachment. I tried "forward" reply and other things.Its working fine. Please let me know if any one have idea for creating script for apple mail "forward as attachment".

  • Problems with Configuration of AdobeInteractiveForms

    Hello everbody, I have installed/deployded - SP11 of Netweaver Developer Studio - Adobe Acrobat Reader 6.02 - Adobe Document Services SP 11 I have cofigured the Adobe Document Services according to the "Adobe Document Service Configuration Guide" Eve