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.

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(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

  • What's the difference between "overloading" and "overriding" in Java

    What's the difference between "overloading" and "overriding" in Java

    hashdata wrote:
    What is the real-time usage of these concepts...?Overriding is used when two classes react differently to the same method call. A good example is toString(). For Object it just returns the class name and the identityHashCode, for String it returns the String itself and for a List it (usually) returns a String representation of the content of the list.
    Overloading is used when similar functionality is provided for different arguments. A good example is [Arrays.sort()|http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#sort(byte%5B%5D)]: all the sort() methods do the same thing (they sort arrays), but one sorts byte-arrays, another one sorts int-arrays, yet another one sorts Object-arrays.
    By the way, you almost certainly mean "real-world" usage. "real-time" (and thus "real-time usage) means something entirely unrelated to your question.

  • 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

  • Extending classes and overriding methods

    If I have a class which extends another, and overrides some methods, if I from a third class casts the extending class as the super class and calls one of the methods which gets overrided, is it the overrided method or the method of the superclass which get executed?
    Stig.

    Explicit cast can't enable the object to invoke super-class's method. Because dynamic binding is decided by the instance. The cast can just prevent you from using methods only defined in sub-class, but it does not let the object to use super-class's method, if the method's been overrided. Otherwise, the polymophism, which is one of the most beautiful feature of Object-Oriented thing, can't be achieved. As far as I know, the only way to use super-class's method is the super keyword in the sub-class, and seems no way for an object to do the same thing (I may wrong, since I haven't read the language spec).
    here's a small test:
    public class Test {
    public static void main(String[] args){
    A a = new B();
    a.method();
    ((A)a).method();
    class A{
    public void method(){
    System.out.println("A's method");
    class B extends A{
    public void method(){
    System.out.println("B's method");
    The output is:
    B's method
    B's method

  • Hiding and restoring table columns from file?

    how i handle hiding and unhiding columns in a jtable is that i have a checkbox for each column, depending on which is checked "on" the tablecolumn is found and added to a vector and removed from the table.
    when the checkbox is checked "off" this vector is searched for the correct tablecolumn, and then added back to the table. this works fine.
    when i close out of the program, i go thru the table and write the visible column names along with its size to file.
    when i re-open the program, i create the table normally, then go thru the file and hide(remove) the tablecolumns found in it..this works fine.
    but when i go back to this checkbox list and try to unhide the tablecolumn, i get an exception
    java.lang.IllegalArgumentException: Cannot format given Object as a Number
         at java.text.NumberFormat.format(NumberFormat.java:219)
         at java.text.Format.format(Format.java:133)
         at javax.swing.JTable$DoubleRenderer.setValue(JTable.java:3397)
         at javax.swing.table.DefaultTableCellRenderer.getTableCellRendererComponent(DefaultTableCellRenderer.java:160)
         at javax.swing.JTable.prepareRenderer(JTable.java:3731)
         at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1149)
         at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
         at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
         at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
         at javax.swing.JComponent.paintComponent(JComponent.java:541)
         at javax.swing.JComponent.paint(JComponent.java:808)
         at javax.swing.JComponent.paintChildren(JComponent.java:647)
         at javax.swing.JComponent.paint(JComponent.java:817)
         at javax.swing.JViewport.paint(JViewport.java:722)
         at javax.swing.JComponent.paintChildren(JComponent.java:647)
         at javax.swing.JComponent.paint(JComponent.java:817)
         at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
         at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
         at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
         at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
         at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)before i unhide the columns, the table is already populated with values. so it might have something to do with that...cuz there is no problems unhiding them if the table contains no data
    any ideas?
    thanks

    If you're interested, this method hides a table column without any modifications of its content:
       public static void setTableColumnVisible(JTable table, int col,                                                                             
                                                  boolean visible, int width) {
          try {
             TableColumn column = table.getColumnModel().getColumn(col);
             if (!visible) {
                column.setMinWidth(0);
                column.setWidth(0);
                column.setMaxWidth(0);
                column.setPreferredWidth(0);
             else {
                column.setWidth(width);
                column.setPreferredWidth(width);
          catch(Exception e) {
             e.printStackTrace();
       }Method use:
    . setTableColumnVisible(table, col, false, 0) hides the column
    . setTableColumnVisible(table, col, true, 100) restores the column to its size of 100
    Hope this helped,
    Regards.

  • ITunes Store: Hiding and unhiding purchases

    I found a link to hide purchases in iCloud ( iTunes Store: Hiding and unhiding purchases).
    It says to "Click Purchased from the Quick Links section on the right side of the iTunes Store". However, I don't see the Quick Links section. Any ideas?

    Click on iTunes Store.  You will find it either on the left sidebar if you have that visible, or on the top right corner of iTunes if the sidebar is not visible.  You will then see Purchased under Quick Links as shown below:

  • Compensation Default and override - Component Id error

    Hi,
    I am working on a fast formula of 'Compensation default and override type' .
    The logic within requires 'component id'. There is an input variable CMP_IV_COMPONENT_ID for this formula type .
    I am attaching the fast formula to a component specific column in the worksheet for a particular plan.
    I back the plan and start it.
    The formula is not getting executed at all.
    I also tried attaching this formula to a normal column (which is not specific to a component) .. But in this case the component id was not recognized and the start Batch process errored out.
    Please let me know how to attach this type of formula to a plan and run it .
    Edited by: 998873 on May 13, 2013 11:34 PM

    Please note ASG_HR_ASG_ID and PAYROLL_ASSIGNMENT_ID are not same in Fusion. That's why it' not returning any value as element entries are created for payroll assignment id. Since you are able to get value for ASG_HR_ASG_ID, it must be setting value for PAYROLL_ASSIGNMENT_ID as well. Please check value for PAYROLL_ASSIGNMENT_ID and EFFECTIVE_DATE context using following code:-
    L_EFFECTIVE_DATE_TEMP='0001/01/01 00:00:00' (Date)
    L_PAY_ASG_ID = GET_CONTEXT( PAYROLL_ASSIGNMENT_ID, -1)
    L_EFFECTIVE_DATE=GET_CONTEXT(EFFECTIVE_DATE,L_EFFECTIVE_DATE_TEMP)
    If it's returning value, it means payroll assignment id and effective date contexts are already set and you don't need to set them explicitly. You can directly get value for STOCK_OPTIONS_NUMBER_OF_SHARES_ASG_ENTRY_VALUE.
    Hope this help!

  • Hiding and Displaying TS UI Controls from LabView

    We have a custom TestStand User Interface, written in LabView, that is a modified 'Simple' User Interface as installed with TestStand.
    When our UI is initialising the TestStand UI controls are immediately displayed with nothing displayed inside them, this looks very untidy. Is there a way of hiding and displaying TS UI controls on demand?
    Regards
    Steve
    Message Edited by SercoSteve on 03-09-2006 09:22 AM
    There are 10 types of people in the world that understand binary, those that do and those that don't.

    TestStand I am still learning, but LabVIEW I know.  There are several things that you could do.  One thing would be a splash screen.  I don't think that this is what you are after, though.
    Each control has a terminal on the block diagram.  If you right click on the terminal, you can create a property node.  There are lots of properties that you can set on a control, including whether it is visible or greyed out.  I think you want to hide the controls and SAVE the VI that way.  Then, when the VI is run, where the control/indicator gets its data, set it to visible with the property node as well.  If this is in a subVI, you might need to create a reference to the control/indicator and pass that into the VI as well. You can then wire it to a property node in the subVI.
    There are several examples on using property nodes that ship with LabVIEW that should be able to get you started.
    Hope that this helps,
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • List what monitors and overrides a specific server have

    Hi,
    I really need help with this!
    I am migrating servers from a very messy scom 2007r2 enviroment.
    I have installed a new scom 2012r2 enviroment and are trying to import server by server. I need to have all monitors and overrides listed soo I know what have been monitored before soo I can set it up in the new enviroment also.
    I can not import whole management packs because then I have all the mess in the new enviroment aswell.
    Soo I need to get a list like this:
    Server1
    Exchange 2007 monitor
    Custom monitor process lanman.exe
    Custom monitor service Print spoolsv
    Override no alerts on print spoolsv
    Is this possible to do? Please please help me!

    For SCOM 2007 R2, Microsoft had develop a tool called Effective Configuration Viewer that can displays the set of rules and monitors that are running on a computer and can export the result into xml file. You can download the file from
    http://www.microsoft.com/en-us/download/details.aspx?id=6742
    Roger
    That was a really nice tool! Never heard of before, thank you very much!

  • Overloading and Overriding

    Why do we need Overloading and Overriding?

    EJP, I'm just curious to know why you mention "*Overloading gives us the power to call a single method and pass it different parameters and the compiler at runtime decided which suitable method to call*" as a wrong answer.Because it is a wrong answer. The action occurs at compile time, not at runtime. The compiler isn't even present at runtime, by definition, so the statement is not just wrong but a contradiction in terms.
    Is there any other reason for having overloading in java?The statement isn't a reason at all. It's just a definition, and an incorrect one, of what method overloading is. A definition is not a reason.
    So why you're asking me for another reason when there hasn't been one provided at all in the entire thread, other than by me, is a complete, utter, and baffling mystery.
    You seem to have the same problem ram has, of confusing 'what' with 'why', and of confusing definitions with reasons. One is bad enough, please let's not have two of you.

  • Regarding the tab Distribution Routes is hided and scheduling button too

    Hi Techies,
    Iam trying to configure the Change Request in Solution Manger 4.0 system while doing so i want to configure in Central Configuration of change management for this what is the tcode available in Solman4.0 and anybody know how to configure the Change request management
    the tab Distribution Routes is hided and scheduling button is also hided in Change Request Management
    solutions rewarded!!
    regards,
    S.Rajeshkumar

    Hi
    I want to access GL item tab account number from MIRO transaction to BADIINVOICE_BADI Method CHANGE_AT_SAVE. I entered the account number in GL account tnumber tab. but parameter TI_RBCO_NEW-BUKRS & TI_RBCO_OLD-BUKRS values are empty inside BADI method.
    Can you suggest me how to find this.
    Regards
    Chandra
    Edited by: princeck on Oct 3, 2011 2:32 PM

  • Difrence bitween overloading and overriding

    Plese give the definition & example for polymorphism

    Polymorphism is of two types
    1) static or design time polymorphism
    2) dynamic or run time polymorphism
    example for design time polymorphism is overloading (i.e) a method with same name shares diff signatures
    For eg: arithmetic(int,int)
    arithmetic(int,int,int)
    example for run time polymorphism is overriding (i.e) a method with same name exists in both parent class and child class.
    At run time it will be decided which method to call based on the object which calls it
    Hope this clarifies yr query
    Regards
    Jansi

  • Change field from read only and override calculation based on radio button

    Hi,
    I have a form in which one of the fields has a simple sum calculation and is set to read only so the user can't change it as it sets a print amount as well.
    But if one of the radio buttons is ticked there is a chance that the print amount needs changing but it can be different based on a few other options so I have managed to set the field so the user can edit it depending on an option but the calculation that sets the value overrides what the user enters. I would like to know if it is possible to change this?
    I use
    this.getField("Quantity_Boxes").readonly = false;
    So the user can edit the field when they select the radio button 'yes' under Mesh_b
    and
    this.getField("Quantity_Boxes").readonly = true;
    So the field goes back to read only when the user selects the 'no' under Mesh_b
    and in the Quantity_Boxes field I use:
    Quantity_Curtains / csn
    Just as a simplified division sum with the decimal places set to 0 so a whole number appears.
    csn is just a hidden field that has an amount set depending on the size of curtain.
    Thanks,
    Bruce

    I have found a solution but caused another problem (well more of an irritation than a problem)
    I have made it so the can field throws a dialogue box asking how many of the item fit into a box, the only problem is that the dialogue box will appear more then once.
    For example I have made a new size know as bespoke and when I select that size and hit return the dialogue box pops up which is fine but when the amount of the product is changed it throws the dialogue box again. I guess this is because the calculation has to be run again but is there anyway of stopping this?
    Here is the code I use in the can field which defines how many curtains are in the box and is used to calculate how many labels need printing out.
    if(this.getField("SizeDrop").value=='LG'){
    event.value = "5"
    } else if (this.getField("SizeDrop").value=='ST'){
    event.value = "8"
    } else if (this.getField("SizeDrop").value=='ME'){
    event.value = "10"
    } else if (this.getField("SizeDrop").value=='SM'){
    event.value = "15"
    } else if (this.getField("SizeDrop").value=='BE'){
    var resp = +app.response("Enter the amount of curtains in a box","","1");
    event.value = resp
    } else {
    event.value = " "
    Thanks,
    Bruce
    EDIT:
    I have found that the dialogue box will appear every time something is changed on the form (even while in the editor as well)

Maybe you are looking for

  • Can't game on my new, strong laptop

    So I'm having a problem. I was able to get my computer, the Pavilion 15-p263nr, on sale this past week, and am very excited. It has a quad core AMD A10-4655M Processor (2.0ghz to 2.8ghz), 8GB of RAM, and an AMD Radeon HD 7620G with 4224MB of graphics

  • How do I place a form on my site.

    I am trying to have a form my users can download to mail to me. Not sure if it needs to be a PDF, or if just a jpg would work. I made the form on a web page and it looks great, but users would have to 'print page" the way I have it now. Any help woul

  • How to create and place a slideshow into an exiting webpage

    I am using DW CC and want to create a slideshow and place it into an existing webpage displaying product images. My initial thought was to use Lightroom to create the HTML or Flash file and place it as an iFrame but I think that may be a clunky and o

  • Windows Mobile Service, getting started, doesn't work.

    I have followed the instructions for creating a mobile data service (several times, under and existing and a new subscription, using an existing and a new database): create the service, download the todo app, build and run it locally (it works), chan

  • Reading Notes in 6.0

    How can I read the notes field in the config.xml This applies to any notes field in the console, not just the JMS Server Specifically, I configure a JMS Server. Then I add to the Notes section a field which has key=value.value.value What call do I ma