Hiding and overriding(look SAMPLE CODE) -is there possible polymorphism?

sample code is there
pls explain how it works
class animal
public void static hide()
system.out.println("the hiding in aniaml")
public void overrriding()
system.out.println("the overriding in aniaml")
class cat extends animal
public void static hide()
system.out.println("the hiding in cat")
public void overrriding()
system.out.println("the overriding in cat")
public static void main(String args[])
cat mycat=new cat()
animal myanimal=(animal)mycat
myanimal.hide()
myanimal.overriding()
output:
the hiding in animal
the overriding in cat

There is polymorphism in one case, where you override the method 'overriding'.
The other method is a static one, which doesnt take part in polymorphism. All static methods are linked at compile time itself.
You can find more details of polymorphism in java here : http://www.javaworld.com/javaworld/javatips/jw-javatip30.html
FeedFeeds : http://www.feedfeeds.com

Similar Messages

  • About hiding and overriding

    Hi,can u tell what is the difference between hiding and overriding.
    Is hiding only applied to class method(static) and overriding only applied to instance method?
    It is a must to use "super" keyword to use a overridden method.Is that right?
    And Look at the code below:
    Can u tell why s.greeting is refer to static method of super while s.name() refer to method of sub?
    What is type and what is class then? Any difference?
    I have read the doc of Java Spec and still do not feel clear about it.Thank you for attention.
    class Super {
    static String greeting() { return "Goodnight"; }
    String name() { return "Richard"; }
    class Sub extends Super {
    static String greeting() { return "Hello"; }
    String name() { return "Dick"; }
    class Test {
    public static void main(String[] args) {
    Super s = new Sub();
    System.out.println(s.greeting() + ", " + s.name());

    It's not necessarily a must to use the "super" keyword in an overridden method. If your class extends some class called "TopClass", and "TopClass" has a constructor, then you must use the super keyword as the first statement in the constructor of your class.
    When you extend a class, your class becomes a type of that class. If you want to override methods, the only requirement (that I know of) is that only the method's body can differ from that of it's super class.
    i.e.
    Here's a method from some super class:
    public boolean mySuperMethod(String s) {
    System.out.println("Hi");
    return true;
    Here's the overridden method from an extended class:
    public boolean mySuperMethod(String s) {
    boolean b = false;
    return b;
    As you can see, you can do whatever you want inside the method, but everything else has to stay the same (as far as I know).
    Here's another example that I did a while back. It's a checkbox that can't be tabbed to and can't accept user actions. I used it simply as an indicator for something.
    import java.awt.*;
    public class NonTraversableCB extends Checkbox
         public NonTraversableCB()
              super();
         public NonTraversableCB(String label)
              super(label);
         public boolean isFocusTraversable() {
              return false;
         public void processEvent() {
              return;

  • Hiding and overriding clarifications

    I am trying to understand the Java language specification document,
    one of the worst technical docs I've seen in 35+ years in the business.
    Right now I'm trying to clarify the implications and meanings of these
    two terms (hiding and overriding) in a very simple environment. Maybe
    someone here can make it clear.
    Context is just basic classes with fields, initializers, constructors, and
    methods; no interfaces, no nested classes. Keep it clear and simple.
    When I create a subclass, I understand that fields and methods are
    inherited. I also understand how hiding of fields works, and how to
    access a hidden field from an external class.
    But methods. Sheesh! At first I thought maybe fields are hidden and
    methods are overridden. But, no, because there's 8.4.10.5 titled
    "Example: Invocation of Hidden Class Methods". So a method can
    be hidden, and a hidden method can be accessed.
    So, here are my questions:
    * What is the difference between overriding a method and hiding a method?
    * How can you tell / demonstrate a method is hidden or overridden?
    * If a method is overridden, is it always inaccessible from an external class?
    * Are there pitfalls to avoid with hiding / overriding methods?
    * Are there features to exploit with hiding / overriding methods?
    * Do instance methods have different behaviors / facilities than
    class methods, as far as hiding and overriding?
    Thanks.

    * What is the difference between overriding a
    method and hiding a method?Overriding a method means the subclass chooses not to use the parent class's implementation. Hiding a method I assume means you declare a method private so that a subclass cannot use it.
    * How can you tell / demonstrate a method is hidden
    or overridden?The modifier private will be applied to methods that are hidden. Overridden methods will have the same signature as the parent and are thus easy to spot as well.
    * If a method is overridden, is it always
    inaccessible from an external class?You're confused. Hidden/private methods affect visibility. Overriding a method doesn't change it's visibility so external classes may or may not be able to access it. It all depends on the access modifiers you've applied
    * Are there pitfalls to avoid with hiding /
    overriding methods?You'd have to provide a specific scenario for this question. This is too open-ended.
    * Are there features to exploit with hiding /
    overriding methods????
    * Do instance methods have different behaviors /
    facilities than
    class methods, as far as hiding and overriding?What you're talking about is static vs. instance methods. Google it, I'm done for now.

  • CS6 problem. When I open the Mask panel, it takes up the entire screen width and the Looks controls disappear, Also, there is a new panel below the Mask panel that seems to have no purpose that I can find. The documentation says "Mask and Look panels - Th

    CS6 problem. When I open the Mask panel, it takes up the entire screen width and the Looks controls disappear, Also, there is a new panel below the Mask panel that seems to have no purpose that I can find. The documentation says "Mask and Look panels - The Mask panel is now placed next to the Look panel. WIth the masking and grading tools placed side-by-side, you can now work faster on the mask workflow." Is there a way to move, hide, or otherwise manipulate the panels for a custom layout? All the examples I can find on the Web show the Looks panel to the left of the Mask panel where the controls are available.

    Ok, here is what I have so far. Appdelete the iWork and reinstalled. Pages and Number work, but not Keynote.
    Now, I downloaded a couple apps that I need, and no matter what I did, the spinning ball came up and the download stopped till it unlocked itself. It is really frustrating because the download was not completed and whatever came through would not mount. Could this issue be the internet connection? Permission fix showed a lot of Airport issues. I will try to run permissions fix again.

  • Hiding and unhiding of Abap code

    hi friends
    can u please help me in hiding and unhiding of abap code(both hiding and unhiding are required)
    Regards
    Hemanth

    Hi,
    Please check this thread for hiding abap code....
    http://www.sap-img.com/abap/program-to-hide-abap-source-code-and-protects-it.htm
    Regards
    Guru

  • The sound no longer works in my husband's iPad and it keeps shutting itself down. This started today. We checked all the settings and everything looks right. Is there something we might be missing?

    The sound no longer works in my husband's iPad and it keeps shutting itself down. This started today. We checked all the settings and everything looks right. Is there something we might be missing?

    Try a reset first: Press and hold both Sleep/Wake and Home buttons until the Apple logo appears.
    If the reset doesn't fix it, try a restore:
    http://support.apple.com/kb/HT1414

  • So my mom set restrictions on my ipod and she forgot the code is there any way of retriving the code

    so my mom set restrictions on my ipod and now she cant remember the code is there any way of getting that code

    Abbieyoyo wrote:
    so my mom set restrictions on my ipod and now she cant remember the code is there any way of getting that code
    No.
    To remove the Restrictions passcode you will need to either...
    Restore the Device as New...
    http://support.apple.com/kb/HT4137
    OR...
    from a Backup created Before the Restrictions Code was set....
    Restore from Backup
    http://support.apple.com/kb/ht1766

  • I need a Sample Code about flash++.h and swc.

    hi,help me !
    i need a Sample Code about flash++.h and swc.
    my Sample Code bitmapdata.cpp:
    #include <AS3/AS3.h>
    #include <Flash++.h>
    using namespace AS3::ui;
    void gettpoint() __attribute__((used,
    annotate(“as3sig:public function gettpoint(x:Number,y:Number):uint”),
    annotate(“as3package:MyLibrary”)));
    void gettpoint()
    double xx;
    double yy;
    inline_as3( “%0 = x;%1 = y\n” : “=r”(xx) : “r”(yy) );
    flash::geom::Point p=flash::geom::Point::_new();
    AS3_Return(xx);
    int main()
    AS3_GoAsync();
    return 0;
    the compile command is “$(FLASCC)/usr/bin/g++” $(BASE_CFLAGS) -O4 bitmapdata.cpp -emit-swc=MyLibrary -o bitmapdata.swc -lFlash++ -lAS3++
    It took me ten minutes to compile,but it can’t work.why?

    Compiling a SWC using Flash++ will result in poor compiler performance if you are using the Flex SDK to compile that SWC into a SWF.
    To get better performance try using the new version of mxmlc that is shipped in the Adobe Gaming SDK.  (Note that this new version of mxmlc doesn't support Flex)
    You will need to install the Gaming SDK and then extract the archive in the "AIR SDK" folder.  Once that archive is extracted you'll notice the new mxmlc compiler in the bin folder.
    Unfortunately compiling a SWF seems to be a little tricky.  You'll notice in the sample Makefile below project that it changes directory into the bin folder before calling ./mxmlc.  Ideally you wouldn't need to do this (like how it worked with the Flex mxmlc).  I'll investigate why that is the case.
    Makefile:
    # Path to your FlasCC SDK folder
    $?FLASCC=/Users/stshongr/builds/alchemy/1.0.0/sdk
    $?GAMINGSDK="/Applications/Adobe Gaming SDK 1.0/AIR SDK/air3-5_p4_sdk_asc2_mac_112112/bin"
    # The folder the source files are in
    $?SRC_FOLDER=$(PWD)
    all:
              "$(FLASCC)/usr/bin/g++" MyLibrary.c -emit-swc=MyLibrary -o MyLibrary.swc -lFlash++ -lAS3++
              cd $(GAMINGSDK) && ./mxmlc -library-path=$(SRC_FOLDER)/MyLibrary.swc $(SRC_FOLDER)/demo.as -o $(SRC_FOLDER)/demo.swf
    clean:
              rm -f *.swf *.swc *.bc *.exe
    MyLibrary.c:
    #include <AS3/AS3.h>
    #include <Flash++.h>
    using namespace AS3::ui;
    void gettpoint() __attribute__((used,
                                    annotate("as3sig:public function gettpoint(x:Number,y:Number):uint"),
                                    annotate("as3package:MyLibrary")));
    void gettpoint()
        double xx;
        double yy;
        inline_as3( "%0 = x;%1 = y\n" : "=r"(xx) : "r"(yy) );
        flash::geom::Point p=flash::geom::Point::_new();
        AS3_Return(xx);
    int main()
        AS3_GoAsync();   
        return 0;
    demo.as:
    package {
        import flash.display.Sprite;
        import flash.text.TextField;
              import flash.events.Event;
        import MyLibrary.CModule;
        public class demo extends Sprite {
                        private var tf:TextField;
            public function demo() {
                addEventListener(Event.ADDED_TO_STAGE, initCode);
            private function initCode(e:Event):void {
                tf = new TextField();
                addChild(tf);
                // start the FlasCC library
                MyLibrary.CModule.startAsync(this);
                // call the function
                                  tf.appendText("OUTPUT:" + MyLibrary.gettpoint(2,2));

  • Impl.h header and snmp samples are not there

    In Solaris9 the fiiles impl.h and the SNMP samples were not there....how can I get them into my system.
    Thanks

    Hi Krisjagan,
    It’s just been declared Deprecated which means that there won’t be any more updates to this.
    It is in fact available as a feature in Server 2012. Pasting some screenshots below from my Lab, you can refer the following related third party article to compare
    your install step is same or not, and whether you configure firewall correct.
    SNMP Extension Fails on Windows 8/Server 2012 when attempting network communication
    https://support.microsoft.com/kb/2771908?wa=wsignin1.0
    How to Install SNMP and Configure the Community String
    https://support.managed.com/kb/a764/how-to-install-snmp-and-configure-the-community-string.aspx
    For detailed information about how you change SNMP to WinRM, you can follow the msdn portal of Windows Remote Management.
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx.
    How to check if a SNMP Trap is received.
    http://michelkamp.wordpress.com/2012/07/02/how-to-check-if-a-snmp-trap-is-received/
    The similar thread:
    Windows Server 2008 R2 or Windows Server 2012 SNMP Version Support
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/9211da18-cbfb-4adf-84be-43f8654767d1/windows-server-2008-r2-or-windows-server-2012-snmp-version-support?forum=winserverManagement
    More information:
    Windows Remote Management
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx
    I’m glad to be of help to you!
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Legalities of using sample code

    Hi there
    just downloaded
    http://labs.adobe.com/technologies/textlayout/demos/
    This is so very very awsome - just wanted to check
    "Adobe permits you to use, modify, and distribute this file
              in accordance with the terms of the Adobe license agreement
              accompanying it." - ok - couldednt find any licence accompaning ti and when i looked around I only got to the SDK licences mozilla and adobe.
    This sample code is kinda what I was looking towards for a project im working on - (well perhaps a reduced version of it).
    Its obviously taken some one a stack of time to get this editor right.
    I was wondering if there was any other agremeents apart for the SDK ones which apply to "editing" and using this sample code?
    Just dotting the I's and crossing the T's before diving in.

    Th source code is in the JDK as an example of the use
    of the invocation API. Its pretty trivial stuff, so I
    can't see why you shouldn't use it.
    There's lots of java code in the JDK for that same
    reason: if we weren't supposed to look at it/use it,
    why is it there ?There is a difference between the reasonable, the moral and the legal.
    You specifically can not take a class out of (for example), src.zip, modify it slightly and then use it as you see fit. That is what the license says legally.
    I am rather certain that any lawyer who is familar with software law in the US will tell you that you can't use it.
    The application of the legal penalty is up to Sun though. And a reasonable person might guess that Sun will not follow up on this. But if Sun did have a problem with a company/product for some other reason and that company/product was using code like this then it would provide Sun a further way to challenge the company/product. And the law on usage like this is rather specific - the defendant would have no recourse, regardless of the outcome of any other facet legal difficulties, but to pull the product from the market.
    But then I am not a lawyer. And my layman's knowledge is only relevant in the US.

  • Looking for sample code using "first_tab" and "next_tab"

    Looking for sample code using "first_tab" and "next_tab". How is it used with ItemID within a dialog box? I've read the reference books - don't understand it.

    Hi Ray,
    There are several ways to do this, and in the example I created, I actually did not end up using shift registers. I've attached some example code that basically multiplies the period by the duty cycle percentage to achieve the number of milliseconds to be high and low.
    You would just need to insert your DIO code in each frame of the sequence structure.
    Hope that helps. Kind regards,
    -Sam F, DAQ Marketing Manager
    Learn about measuring temperature
    Learn how to take voltage measurements
    Learn how to measure current
    Attachments:
    70_PWM_Example.vi ‏23 KB

  • Looking for sample code to create my own pub/sub!

    I am a new bee in JMS. So I would really appreciate if
    some one could give me some hint to start up with my school project. I am looking for a sample Java code that will:
    For the Publisher:
    1. Connect to a broker [create it, if it does not exist]
    2. Create a publisher/destination.
    3. Create a pub-sub queue
    4. Publish a message
    5. Ack or Nak depending on if the subscriber got or did not get the message.
    For the Subscriber:
    1. Connect to a broker [create it, if it does not exist]
    2. Subscribe to the broker
    3. Subscribe to the Queue
    4. Show an received messages on the console.
    Here are the command line params for both the Publisher and subscriber:
    runPub 127.0.0.1:7676 myTestBroker myQueue "this is my message"
    runSub 127.0.0.1:7676 myTestBroker myQueue
    Please tell me if there are similar java code that will do all this and work with ANY JMS compatible client. i.e. I should not have to use the Admin tool of any JMS Server (MQSeries, iPlanet, SonicMQ etc etc). The code should follow the JMS spec and do this programmatically.
    Thank you very very much in advance for doing this great favor.
    With regards,
    Amir.

    Thanks a lot for that hint. I think that's a great tutorial for a beginner. I could compile those sample codes from chapter 4 with out any problem, but could not run it. I also installed j2sdkee1.3.1 and updated my classpath according to the spec. But when I tried to run the "j2ee -verbose" command it was giving me the following error message:
    ERROR: Set J2EE_HOME before running this script.
    Any advise for me that I should follow next. Thanks again.

  • Looking for sample code of pwm output with Labview 7

    we are looking for sample code in LabView 7 for producing a pwm output. We are current using a 3rd party digital I/O board and just want to generate a pwm output on several of the bits.

    Hi Ray,
    There are several ways to do this, and in the example I created, I actually did not end up using shift registers. I've attached some example code that basically multiplies the period by the duty cycle percentage to achieve the number of milliseconds to be high and low.
    You would just need to insert your DIO code in each frame of the sequence structure.
    Hope that helps. Kind regards,
    -Sam F, DAQ Marketing Manager
    Learn about measuring temperature
    Learn how to take voltage measurements
    Learn how to measure current
    Attachments:
    70_PWM_Example.vi ‏23 KB

  • Looking for sample code to decrypt MYSAPSSO2 session cookie

    Hello,
    I am looking for a sample code to decrypt MYSAPSSO2 session cookie and get the username out of it.

    Hi Roy,
    if you just need the username the easiest way is to grab the Cookie and Decode it using Base64. The username is contained in cleartext.
    e.g.
    MYSAPSSO2 Ticket as fetched from Browser:
    AjExMDAgABFwb3J0YWw6bXRyaWNhcmljb4gAE2Jhc2ljYXV0aGVudGljYXRpb24BAApNVFJJQ0FSSUNPAgADMDAwAwADRDAxBAAMMjAwODA3MjUwNTA3BQAEAAAACAoACk1UUklDQVJJQ0%2F%2FAQUwggEBBgkqhkiG9w0BBwKggfMwgfACAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHATGB0DCBzQIBATAiMB0xDDAKBgNVBAMTA0QwMTENMAsGA1UECxMESjJFRQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMDgwNzI1MDUwNzU5WjAjBgkqhkiG9w0BCQQxFgQUxUGK!5EDTrHQErPQCVJhEySzTBAwCQYHKoZIzjgEAwQvMC0CFQCD3K2A2hrgpNa5EceiDXjRN309ewIUTM3DJi8QTxmk%2FJez!rjnFlTM3BQ%3D
    Decoded Ticket using Base64:
    1100 uFFFD portal:mtricaricou02C6uFFFD basicauthentication uFFFD
    MTRICARICO uFFFD 000 uFFFD D01 uFFFD 200807250507 uFFFD uFFFDuFFFDuFFFD
    If you want to do it programmatically using any libraries to completely decode the ticket, check the validity and also access the certificate information inside the ticket you can use a SAP Extension called SAP SSOEXT (Goto service.sap.com/swdc and search for SSOEXT => The package also contains documentation and samples for various programming langauges such as JAVA).
    This one needs dynamic libraries or shared libraries to be linked.
    There also is a pure JAVA approach.
    Have a look at this:
    http://www.zope.org/Members/Dirk.Datzert/MySapSsoSupport/
    But:
    The approach of decrypting the cookie does not really make since when you are in a SAP system it is more intended for 3rd party systems in order to implement SSO.
    Hope this helps
    Cheers

  • Sample code to find duplicated entries in internal table and mark them?

    We have one internal table called itab1 which contains the following fields:
    f1 (key field)
    f2 (non-key field)
    f3 (non-key field)
    The business scenario is f1, f2, and f3 are one to one relationship to each other, or in other word, f2 or f3 can't be duplicated with the the same values for different f1 (key field) records. We will move the check result of the duplication into another internal table itab2 which contains f1, f2, f3, f4, and f5 where f1, f2, and f3 are the same ones as in itab1, f4 will get the value "Yes" to mark duplicated for f2 (or "No" to mark non-duplicated), and f5 will get the value "Yes" to mark duplicated for f3 (or "No" to mark non-duplicated).
    We know that through the loop of itab1, the above logic can be done to fill in f4 and f5 value for each row with either "Yes" or "No".
    Just give an example of how itab2 will look like after the coding:
    f1----f2--f3--f4(f2 duplicated?)---f5(f3 duplicated?)
    A----01-X0YesNo--
    B----01-X1YesYes--
    C----02-X1NoYes--
    Could any ABAP expert here show us the sample code to generate itab2 in loop of itab1 to find the duplicated entries of f2 and f3 and then populated the corresponding row values for f4 and f5 with "Yes" or "No"? We will give you reward points!

    TYPES: BEGIN OF ty_1,
    f1,
    f2(2),
    f3(2),
    f4,
    f5,
    END OF ty_1.
    TYPES: BEGIN OF ty_2,
    type(2),
    value(2),
    END OF ty_2.
    DATA: itab1 TYPE STANDARD TABLE OF ty_1 WITH HEADER LINE,
          itab2 TYPE TABLE OF ty_2 WITH HEADER LINE.
    DATA: f2_c TYPE sy-tabix VALUE 0,
         f3_c TYPE sy-tabix VALUE 0,
         curr_f2 LIKE itab1-f2,
         curr_f3 LIKE itab1-f3.
    itab1-f1 = 'A'.
    itab1-f2 = '01'.
    itab1-f3 = 'X0'.
    APPEND itab1.
    itab1-f1 = 'B'.
    itab1-f2 = '01'.
    itab1-f3 = 'X1'.
    APPEND itab1.
    itab1-f1 = 'C'.
    itab1-f2 = '02'.
    itab1-f3 = 'X1'.
    APPEND itab1.
    SORT itab1 BY f1 f2 f3 AS TEXT.
    LOOP AT itab1.
      IF sy-tabix EQ 1.
        curr_f2 = itab1-f2.
        curr_f3 = itab1-f3.
      ENDIF.
      IF itab1-f2 NE curr_f2.
        f2_c = 0.
        curr_f2 = itab1-f2.
      ENDIF.
      IF itab1-f3 NE curr_f3.
        f3_c = 0.
        curr_f3 = itab1-f3.
      ENDIF.
      f2_c = f2_c + 1.
      f3_c = f3_c + 1.
      IF f2_c > 1.
        itab1-f4 = 'X'.
        MODIFY itab1.
        itab2-type = 'f2'.
        itab2-value = itab1-f2.
        APPEND itab2.
      ENDIF.
      IF f3_c > 1.
        itab1-f5 = 'X'.
        MODIFY itab1.
        itab2-type = 'f3'.
        itab2-value = itab1-f3.
        APPEND itab2.
      ENDIF.
    ENDLOOP.
    DELETE ADJACENT DUPLICATES FROM itab2.
    LOOP AT itab2.
      IF itab2-type = 'f2'.
        LOOP AT itab1 WHERE f2 = itab2-value AND f4 NE 'X'.
          itab1-f4 = 'X'.
          MODIFY itab1.
        ENDLOOP.
      ELSE.
        LOOP AT itab1 WHERE f3 = itab2-value AND f5 NE 'X'.
          itab1-f5 = 'X'.
          MODIFY itab1.
        ENDLOOP.
      ENDIF.
    ENDLOOP.
    Edited by: Ramiro Escamilla on Apr 5, 2008 1:45 AM
    changed the code, now should work

Maybe you are looking for

  • How to  use get_value in oracle tags

    Hi My requirement is I am calling a dynamic page by a url from other dynamic page. I have to capture the parameter values in the other dynamic page. I used get_value('title'); But I am getting error........Pls solve this issue.......... Regards, Radh

  • Occasion network problem

    I have been running my system for 3 months and over that period of time I have had problems with the integrated ethernet twice. The first time, the system behaved as if it had no network connectivity. The second time I was able to communicate over th

  • Movement Tpes

    Hi. Can anybody post the moment types used in SD point of View and their description means where it is use? I will give reward points for best answers Thanks Karrun

  • India Localizaion R12 PO interface with taxes

    Hi, Please help me to provide india localization PO interface tables and details In R12. I want to upload tax information also. Please give the tables. If documents available with you please forward it to me ([email protected]) Thanks Prasanna

  • How to convert vob files to mov files

    can anyone assist here? i have the mac osx 10.6.7. Cheers