Please explain the code below

What will be the output of the following code? Can I get some detail explanation?
class A{
    void show(){
        System.out.println("A");
interface my{
    public void show();
class B extends A{
   B(my m){
       m.show();
    public void show(){
        System.out.println("B");
public class test implements my{
    public void show(){
        System.out.println("test");
    public static void main(String args[]){
      test t=new test();
      B b=new B(t);
      b.show();
}Thanks

What will be the output of the following code? Can I
get some detail explanation?Well, I guess you were not able to figure out HOW you got that output. Should have been a li'l more clear in your question. Never mind now... here is my understanding of the code.
1) The program starts at main()
2) creates an object for test called t (does nothing more than this since it does not have a constructor defined by you!!)
3)creates an object for B whose constructor takes an object argument of type my. you send t becuase test implements my.
4)calls the show method of m in the constructor.
5)now, where is the definition of show() for m? Its in test. So now, that show() is executed and hence "test" is printed first.
6)all done, it comes back to the main() to go to the next statement.
7)calls the show() of b.
8)this version of show asks to print "B" and hence the output.
Was this detailed explanation enough? I hope so... ;-)

Similar Messages

  • Please explain the code given .....

    FileInputStream fstream = new FileInputStream("Emp.txt");
    DataInputStream dstream = new DataInputStream(fstream);
    BufferedReader bf = new BufferedReader(new InputStreamReader(dstream));
    String data = null;
    String comma = ",";
    while((data = bf.readLine()) != null)

    http://java.sun.com/docs/books/tutorial/essential/io/streams.html

  • Please check the Code snippet and detail the difference

    Please go through the two code snippets given below...
    Can some one please let me know if using generics is a better way to denote the signature and if yes, why is it so?
    Thank you
    Two classes:
    class SimpleStr {
         String name = "SimpleStr";
         public SimpleStr(String name) {
              this.name = name;
         public String getName() {
              return this.name;
         public String toString() {
              return getName();
    class MySimpleStr extends SimpleStr {
         String name = "MySimpleStr";
         public MySimpleStr(String name) {
              super(name);
              this.name = name;
         public String getName() {
              return this.name;
         public String toString() {
              return getName();
    Code Snippet 1:
    class AnotherSimpleStr {
         public <S extends SimpleStr>S getInfo() {
              return (S)new MySimpleStr("val3");
    Code Snippet 2:
    class AnotherSimpleStr {
         public SimpleStr getInfo() {
              return new MySimpleStr("val3");
    }

    Also, please see the code below, the getInfo() method is not taking care of Type safety right??!!!!
    class AnotherSimpleStr {
         public <S extends SimpleStr>S getInfo() {
              return (S)new Object();
         public <S extends SimpleStr>S getInfoAgain(Class<S> cls) {
              return (S)new MySimpleStr("Val");
    }

  • Can you explain the code ?

    Hi friends i have got a code its working fine but i am not getting the concept in the code can any one tell which line is the ITAB declaration and which lines are workarea declarations of the structure.
    TYPES: BEGIN OF ST_ZWS,
                RADIO TYPE C,
                DESCRIPTION TYPE ZRIF_WS-DESCRIPTION,
          END OF ST_ZWS.
    DATA: IT_ST TYPE TABLE OF ST_ZWS,
           WA_ST TYPE ST_ZWS,
          IT_ZWS TYPE ZWS,
          WA_ZWS TYPE ZWS.
    Please explain the code here...

    hello
    the code is as follows:
    This part of the code defines structure st_zws.
    TYPES: BEGIN OF ST_ZWS,
    RADIO TYPE C,
    DESCRIPTION TYPE ZRIF_WS-DESCRIPTION,
    END OF ST_ZWS.
    Based on the above defined structure, this statement defines one internal table
    DATA: IT_ST TYPE TABLE OF ST_ZWS,
    This statement defines work area to the above defined Internal table
    WA_ST TYPE ST_ZWS,
    This statement defines another internal table with reference to ZWS
    IT_ZWS TYPE ZWS,
    This statement defines workare to the above defined internal table
    WA_ZWS TYPE ZWS.
    cheers!!!

  • Please explain the use of all the below movt types

    Hi friends,
    Can you Please explain the use of all the below movt types and how it is triggered.
    901     GR Area for Production
    902     GR Area External Rcpts
    904     Returns
    910     GI Area General
    911     GI Area for Cost Center
    912     GI Area Customer Order
    913     GI Area - Fixed Assets
    914     GI Area Production Orders
    915     Fixed Bin Picking Area
    916     Shipping Area Deliveries
    917     Quality Assurance
    920     Stock Transfers (Plant)
    921     Stock Transfers (StLoc)
    922     Posting Change Area
    980     R/3 --> R/2 cumulative
    998     Init.entry of stock bal.
    999     Differences
    Regards,
    Balu R.V

    Hi,
    The below mentioned objects are interim storage types, not movement types.
    Interim storage types are used as a sort of bridge between IM and WM.
    MZ

  • Please explain,  the job of the  "ASSIGN COMPONENT ".

    Please read this popular example appended below. I am newbie to ABAP.
    At the end of the execution the code is printing 33. Don't get it.
    Please explain,  the job of the  "ASSIGN COMPONENT ". How or why it is printing value 33.  What is the meaning of the statement, "ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>." ?
    DATA: BEGIN OF LINE,
    COL1 TYPE I VALUE '11',
    COL2 TYPE I VALUE '22',
    COL3 TYPE I VALUE '33',
    END OF LINE.
    DATA COMP(5) VALUE 'COL3'.
    FIELD-SYMBOLS: <F1>, <F2>, <F3>.
    ASSIGN LINE TO <F1>.
    ASSIGN COMP TO <F2>.
    DO 3 TIMES.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
    WRITE <F3>.
    ENDDO.
    ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
    WRITE / <F3>.
    11 22 33
    33

    DATA: BEGIN OF LINE,
    COL1 TYPE I VALUE '11',
    COL2 TYPE I VALUE '22',
    COL3 TYPE I VALUE '33',
    END OF LINE.
    DATA COMP(5) VALUE 'COL3'.
    FIELD-SYMBOLS: <F1>, <F2>, <F3>.
    ASSIGN LINE TO <F1>.
    ASSIGN COMP TO <F2>.      "here you are assigning the column name which is COL3 to <f2>.
    DO 3 TIMES.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
    WRITE <F3>.
    ENDDO.
    ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
    ASSIGN 'COL3' of structure <f1> to <f3>. "it is equal to above statement.
    WRITE / <F3>.
    11 22 33
    33
    ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>. means
    assigining  COL3  value of the structure <f1> to <f3>, so value is 33 , it will be assigned to <f3> .it prints 33.

  • Please explain the magic! (Question)

    The ActionScript snippet below is from the BlaseDS chat sample app. Can someone please explain the magic that declares the chatMessage property of AsyncMessage.body (IMessage.body?) object? It's not in the docs anywhere so I'm guessing it is not built into AsyncMessage. And it's not defined in any of the sample app source files.
    Coming from a strongly-typed development world, seeing a property that apparently has no declaration and is not explicitly instantiated does not pass the sniff-test.
    Thanks.
    <mx:Script>
      <![CDATA[
       import mx.messaging.messages.AsyncMessage;
       import mx.messaging.messages.IMessage;
       private function send():void
        var message:IMessage = new AsyncMessage();
        message.body.chatMessage = msg.text;
        producer.send(message);
        msg.text = "";
       private function messageHandler(message:IMessage):void
        log.text += message.body.chatMessage + "\n";
      ]]>

    Hold your nose, because that is the dynamic "feature" of Actionscript.  Pretty much every class derives from Object (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Object.html) which is a dictionary of key-value property pairs.  The {"chatMessage", msg.text as Object} pair is created upon assignment.
    I am fairly new to Flex/AS, and while not having to declare types is convenient for quick and dirty coding, I try to avoid it in production code...I have been bitten by refactoring a class and not catching all the places where it was referenced dynamically.  I'm sure there are comprehensive pro and con arguments out there.

  • Please explain the following terms in SRM

    Hi Forum,
    I am new to SRM and trying to understand some general terms and concepts in SRM.
    Please explain the meaning of below jargons if possible with an example and what is their use in SRM bussiness scenarios...
    1. Company Code
    2. Account Assignment Category - CC, OR etc
    3. Cost Center
    4. Document Types
    5. Transaction Types
    6. Movement Types
    7. Storage Location
    8. Plants
    9. Central Person
    10. Business Partner
    I am trying to understand what is the relevance of above things in SRM/ECC ?
    Thanks,
    Vivek

    Vivek
    It would be great if you go through http://help.sap.com/saphelp_srm30/helpdata/en/8d/f6a93e08503614e10000000a114084/frameset.htm
    This will help you clear most of your queries.
    Regards,
    Nikhil

  • Can anyone please explain this code to me?

    I am a new (junior)programmer?Can anyone please explain this code to me in lame terms? I am working at a client location and found this code in a project.
    _file name is AtccJndiTemplate.java_
    Why do we use the Context class?
    Why do we use the properties class?
    package org.atcc.common.utils;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    import java.util.logging.Logger;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import org.springframework.jndi.JndiTemplate;
    public class AtccJndiTemplate extends JndiTemplate
      private static Logger logger = Logger.getLogger(AtccJndiTemplate.class.getName());
      private String jndiProperties;
      protected Context createInitialContext()
        throws NamingException
        Context context = null;
        InputStream in = null;
        Properties env = new Properties();
        logger.info("Load JNDI properties from classpath file " + this.jndiProperties);
        try
          in = AtccJndiTemplate.class.getResourceAsStream(this.jndiProperties);
          env.load(in);
          in.close();
        catch (NullPointerException e) {
          logger.warning("Did not read JNDI properties file, using existing properties");
          env = System.getProperties();
        } catch (IOException e) {
          logger.warning("Caught IOException for file [" + this.jndiProperties + "]");
          throw new NamingException(e.getMessage());
        logger.config("ENV: java.naming.factory.initial = " + env.getProperty
    ("java.naming.factory.initial"));
        logger.config("ENV: java.naming.factory.url.pkgs = " + env.getProperty
    ("java.naming.factory.url.pkgs"));
        logger.info("ENV: java.naming.provider.url = " + env.getProperty
    ("java.naming.provider.url") + " timeout=" + env.getProperty("jnp.timeout"));
        context = new InitialContext(env);
        return context;
      public String getJndiProperties()
        return this.jndiProperties;
      public void setJndiProperties(String jndiProperties)
        this.jndiProperties = jndiProperties;
    }

    Hi,
    JNDI needs some property such as the
    java.naming.factory.initial
    java.naming.provider.url
    which are needed by the
    InitialContext(env);
    where env is a properties object
    Now if you can not find the physical property file on the class path
    by AtccJndiTemplate.class.getResourceAsStream(this.jndiProperties);
    where the String "jndiProperties" get injected by certain IOC ( inverse of control container ) such as Spring framework
    if not found then it will take the property from the system which will come from the evniromental variables which are set during the application start up i.e through the command line
    java -Djava.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory -Danother=value etc..
    I hope this could help
    Regards,
    Alan Mehio
    London,UK

  • Urgent-Please check the code

    Hi There,
    Could you please have a look at the code below and suggest whether I am using If else in good manner or not?
    User will enter Start date and end date at begbalance level and account value is also calculated at begbalance then we need to copy that value to months starting from the Start date month so I need to convert the integer value of month to string month.but it is giving error.
    var monthsdiff,endyear,startyear,startmonth,endmonth;
    fix("budget","begbalance",..........)
    Fix("hsp_inputvalue")
    "Account1"
    startmonth=@INT(@MOD("Date-start",10000)/100);
    Monthsidff=..........;
    if(startmonth=1)
    &startmon= "JAN";
    elseif(startmonth=2)
    &startmon= "FEB";
    elseif(startmonth=3)
    &startmon= "MAR";.........till dec
    endif
    if(endmonth=1)
    &endmon= "JAN";
    elseif(endmonth=2)
    &endmon= "FEB";
    elseif(endmonth=3)
    &endmon= "MAR"...till dec
    endif
    fix(&startmon)
    if(startyear==&CurrYear and endyear==&CurrYear)
    "Account1"=("Account1"/12) *monthsdiff;
    endfix
    else
    "Account1"->"may"=("Account1"/12) * monthsdiff;
    endfix
    endif
    endfix
    endfix
    here Curryear is 2011.
    Thanks
    Edited by: user10760185 on Sep 20, 2011 2:19 AM

    It looks like you are trying to assign a value to a substitution variable in your calc, you can't do that. ^^^Until quite recently, yes, but now if you read Robb Salzmann's blog and grab his CDF: http://codingwithhyperion.blogspot.com/2011/08/create-and-update-substitution.html
    Btw, beyond Robb's code being a cool hack, I'm not entirely sure I'd want to change sub var values on the fly but it at least appears to be possible.
    Regards,
    Cameron Lackpour

  • 2 GB Limit – Please explain the concept

    I have more than 35000 photos already uploaded into Revel.
    In order to continue to remain a Free member, shall I have to delete all my photos and keep only within 2 GB limit?
    Please explain the new concept... Thanks!

    You may continue to use revel free of charge with the new model change, however, if you have stored more than 2 GB of files, then you will be unable to upload any additional photos/videos until you delete some files to take you below the limit or subscribe to get unlimited uploads.
    Pattie

  • Could someone show me the correct way to use the Vector in the code below?

    Would someone mind explaining to me why I am getting a NullPointerException when I run the code below? I initialized the vector in the constructor so it should follow through the whole class right? What would be the right way to do it?
    import java.util.Vector;
    public class AlumniDirectory
        private String faculty;
        private static Vector alumni;
        /** Constructor reads faculty Name and inits new vector **/
        public AlumniDirectory(String facultyIn)
            Vector alumni = new Vector();      
            faculty = facultyIn;      
        /** Method adds a new Alumni to the list **/
        public void addAlumnus(Object o)
            alumni.addElement(o);
        /** Method removes a Alumni from the list **/
        public void removeAlumnus(Object o)
            alumni.removeElement(o);      
        /** Method searches for Alumni by last name and graduation year **/
        public void searchAlumnus(String lastNameIn, int years)
          // Code will go here eventually  
        }

    And probably you want a list of Alumni not a vector of Objects. So try this:
    import java.util.List;
    import java.util.ArrayList;
    public class AlumniDirectory{
        private final String faculty;
        private final List<Alumnus> alumni = new ArrayList<Alumnus>();
        /** Constructor reads faculty Name and inits new vector **/
        public AlumniDirectory(String facultyIn)
            faculty = facultyIn;      
        /** Method adds a new Alumni to the list **/
        public void addAlumnus(Alumnus alumnus)
            alumni.add(alumnus));
        /** Method removes a Alumni from the list **/
        public void removeAlumnus(Alumnus alumnus)
            alumni.remove(alumnus);      
        /** Method searches for Alumni by last name and graduation year **/
        public void searchAlumnus(String lastNameIn, int years)
          // Code will go here eventually  
        }-Puce
    Edited by: Puce on Oct 23, 2007 7:43 PM
    Edited by: Puce on Oct 23, 2007 7:46 PM

  • A consent for a new eula, please explain the ramification of these new terms

    4. Your Compliance With This Agreement.
    You acknowledge that your compliance with the terms of this Agreement may require you to provide certain notices to, obtain certain rights from, and impose certain obligations on your Clients and/or users of the websites hosted by the Services. To that end, you agree that each website for which Adobe provides Services on your behalf (including, if you are a Partner, your Clients’ websites) will contain a clear and conspicuous link to a terms of use and a privacy policy that comply with all applicable laws, rules, and regulations.
    5. Partner Obligations.
    (c) You are responsible for your Clients’ compliance with applicable laws in connection with their use of the Services.
    (g) You have or will obtain all rights necessary for you to grant Adobe the licenses granted in Section 16 (“Content”), below.
    16. Content.
    You (if you are a Site Owner) or your End Users (if you are a Partner), and/or each such party’s respective licensors, retain ownership of any information, content and/or materials that they submit in the course of using the Services (“Content”); however, Adobe needs certain rights to Content in order to provide the Services. Accordingly, you hereby grant to Adobe and its service providers and designees a worldwide, non-exclusive, transferable, sublicensable (through multiple tiers), royalty-free, perpetual, irrevocable right and license, without compensation to you: to use, reproduce, distribute, adapt (including without limitation edit, modify, translate, and reformat), create derivative works of, transmit, publicly display and publicly perform such Content, in any media now known or hereafter developed.
    please explain the ramification of these new terms
    Thank you,
    Lana

    Hi guys,
    Correct as Liam noted there are various topics on these concerns. 
    However if still having issues/concerns I would suggest posting in the original thread below after reviewing Magda's response.
    - http://forums.adobe.com/message/4353638
    Kind regards,
    -Sidney

  • Sorry, Flagfox has encountered a problem. Please copy the report below and post it on our forums with a detailed explanation of what you were doing at the time so we can attempt to fix your issue. (English please) Flagfox version null (missing IPDB!)

    Sorry, Flagfox has encountered a problem. Please copy the report below and post it on our forums with a detailed explanation of what you were doing at the time so we can attempt to fix your issue. (English please)
    Flagfox version null (missing IPDB!)
    ERROR MESSAGE: Fatal Flagfox startup error!
    EXCEPTION THROWN: TypeError: ExtensionManager.getItemForID(id) is null
    STACK TRACE: startup()@file:///C:/Documents%20and%20Settings/Vanessa%20Ecret/Programdata/Mozilla/Firefox/Profiles/9eyewkfc.default/extensions/%7B1018e4d6-728f-4b20-ad56-37578a4de76b%7D/chrome/flagfox/modules/flagfox.jsm:40
    ([object ChromeWindow])@file:///C:/Documents%20and%20Settings/Vanessa%20Ecret/Programdata/Mozilla/Firefox/Profiles/9eyewkfc.default/extensions/%7B1018e4d6-728f-4b20-ad56-37578a4de76b%7D/chrome/flagfox/modules/flagfox.jsm:160
    Flagfox_loadForThisWindow([object Event])@chrome://flagfox/content/overlay.xul:16
    BROWSER: Mozilla Firefox 3.6.6/20100625231939 (Gecko 1.9.2.6/20100625231939) using locale en-US on WINNT x86-msvc
    This error and a Flagfox preferences dump has been sent to Tools -> Error Console. Please report this and any related errors so we can investigate your problem. Conversely, if you don't report this then it probably won't get fixed.
    == i was update

    Sorry, the Flagfox extension has encountered a problem. The following error output and a Flagfox preferences dump has been sent to Tools -> Error Console.
    FLAGFOX VERSION: 4.1.x (missing IPDB!)
    ERROR MESSAGE: Fatal Flagfox startup error!
    EXCEPTION THROWN: TypeError: addon is null
    STACK TRACE:
    (null)@resource://flagfox/flagfox.jsm:70
    safeCall((function (addon) {try {FlagfoxVersion = addon.version;var ip4db = addon.getResourceURI(IPv4DBfilename).QueryInterface(Components.interfaces.nsIFileURL).file;var ip6db = addon.getResourceURI(IPv6DBfilename).QueryInterface(Components.interfaces.nsIFileURL).file;ipdb.init(ip4db, ip6db);checkIPDBage();ready = true;} catch (e) {handleStartupError(e);}}),null)@resource://gre/modules/AddonManager.jsm:48
    ([object Object])@resource://gre/modules/AddonManager.jsm:897
    AOC_callNext()@resource://gre/modules/AddonManager.jsm:118
    (null)@resource://gre/modules/AddonManager.jsm:892
    PL_getAddon("{1018e4d6-728f-4b20-ad56-37578a4de76b}",(function (aAddon) {if (aAddon) {safeCall(aCallback, aAddon);} else {aCaller.callNext();}}))@resource:///modules/PluginProvider.jsm:79
    callProvider([object Object],"getAddonByID",null,"{1018e4d6-728f-4b20-ad56-37578a4de76b}",(function (aAddon) {if (aAddon) {safeCall(aCallback, aAddon);} else {aCaller.callNext();}}))@resource://gre/modules/AddonManager.jsm:76
    ([object Object],[object Object])@resource://gre/modules/AddonManager.jsm:888
    AOC_callNext()@resource://gre/modules/AddonManager.jsm:124
    (null)@resource://gre/modules/AddonManager.jsm:892
    (null)@resource:///modules/XPIProvider.jsm:3047
    ([object Array])@resource:///modules/XPIProvider.jsm:4864
    (0)@resource:///modules/XPIProvider.jsm:3867
    BROWSER: Mozilla Firefox 7.0.1 (Gecko 7.0.1 / 20110928134238)
    OS: Windows NT 6.1 (WINNT x86-msvc windows)
    LOCALE: en-us content / en-us UI / en-us OS
    Select and copy the error report above. In order to fix this problem for you and others, please read and follow the troubleshooting and bug reporting instructions on the Flagfox support forums. Please post an abundance of information with any error reports, namely what you were doing at the time that may have triggered this. (English please)

  • Please check the code

    I AM TRYING TO REPLICATE THE ADDRESS OF EQUIPMENT FROM ECC TO CRM.
    I AM ABLE TO REPLICATE THE IDENTIFICATION NUMBER.
    WHILE USING THE SAME FUNCTION MODULE FOR ADDRESS, THE ADDRESS IS NOT GETTING REPLICATED.
    PLEASE CHECK THE CODE AND TELL ME WHAT PRE-REQUISITES MUST BE TAKEN INTO CONSIDERATION AND IS THERE ANY MISTAKE FROM ME.
    FULL POINTS WILL BE REWARDED.
    ITS VERY VERY URGENT.
    METHOD IF_EX_CRM_EQUI_LOAD~ENLARGE_COMPONENT_DATA.
    **Data declarations
    DATA:
        ls_equi          type crmt_equi_mess,
        ls_comp          type ibap_dat1,
        ls_comp_det1     TYPE IBAP_COMP3,
        ls_address_data  type ADDR1_DATA,
        ls_object      type comt_product_maintain_api,
        ls_object1     type comt_product,
        lv_object_id   type IB_DEVICEID,
        lv_object_guid type IB_OBJNR_GUID16.
    **Map Sort field from ECC to CRM
    Read table it_equi_dmbdoc-equi into ls_equi index 1.
    lv_object_id  = ls_equi-equnr.
    move is_object to ls_object.
    move ls_object-com_product to ls_object1.
    lv_object_guid = ls_object1-product_guid.
    move is_component to ls_comp.
    ls_comp_det1-deviceid    = lv_object_id.
    ls_comp_det1-object_guid = lv_object_guid.
    ls_comp_det1-EXTOBJTYP   = 'CRM_OBJECT'.
    ls_comp_det1-ibase       = ls_comp-ibase.
    ls_address_data-roomnumber = '1000'.
    ls_address_data-floor = '10'.
    ls_address_data-country = 'US'.
    CALL FUNCTION 'CRM_IBASE_COMP_CHANGE'
      EXPORTING
       i_comp                       = ls_comp
       I_COMP_DET             = ls_comp_det1
       I_ADDRESS_DATA     = ls_address_data
      I_ADDRESS_ADMIN           =
      I_PARTNER                 =
      I_DATE                    =
      I_TIME                    =
    EXCEPTIONS
      DATA_NOT_CONSISTENT       = 1
      IBASE_LOCKED              = 2
      NOT_SUCCESFUL             = 3
      OTHERS                    = 4
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    ENDMETHOD.

    Hi S B,
    May I the procedure for the replication of serialnumber into device ID that is Identification field In Ibase.
    And one more thing need this to be codded in the standard badi or needed an copy of the implementation .
    plz help me as u already have done the requirement.
    u will be twice rewarded.
    Thanking u in advance for the reply.
    Sree.

Maybe you are looking for