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;

Similar Messages

  • 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.

  • About overloading and overriding

    I hava a Java code like this:
    class Homer {
    float doh(float f) {
    System.out.println("doh(float)");
    return 1.0f;
    char doh(char c) {
    System.out.println("doh(string)");
    return 'd';
    class Bart extends Homer { 
    float doh(float f) {
    System.out.println("doh(float)");
    return 1.0f;
    class Hide {
    public static void main(String[] args) {
    Bart b = new Bart();
    b.doh('x');//compiler error in this line
    b.doh(1);
    b.doh(1.0f);
    An error was ocurred:reference to doh is ambigous
    Who can told me why?

    andy.g
    you are wrong!
    you cannot undertand what is the different between
    overlaoding and overiding!sorry for the wrong answer.
    the point is the super-class's method with most specific signiture has the same priority as the sub-class's method that could match(not exactly the same, but can be promoted, like char to float) the signiture during method binding/finding. java always put the current class's method at the first place, but when a method in super-class is more specicif in signiture, the compiler can't determin which one to use.
    actually, there is nothing related to overriding in this case, e.g.:
    class A{
      char method(char c){.....}
    class B extends A{
      //nothing's been overrided
      float method(float f){......}
      public static void main(String[] args){
         B b = new B();
         b.method('c');  //compiler error.
    }so it is definetely a priority's problem, the super class's methods do not have the same prority as the sub-class's.

  • 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

  • HT1338 How about hiding app store from my iPad

    How about hiding app store from my iPad

    Yes, in Restrictions:
    Settings > General > Restrictions > Enable Restrictions > (Set Passcode) > ALLOW: now choose whether you want to restrict all three options regarding apps and the iTunes Store

  • Is there another way of getting apps from the appstore without putting your credit card number in, ive heard about the itunes gift card thing can anybody just give me more info about that and how i can buy free things free things from the appstorepls help

    Is there another way of getting apps from the appstore without putting your credit card number in, ive heard about the itunes gift card thing can anybody just give me more info about that and how i can buy free things free things from the appstore...pls help as im only a teenager and have no credit credit and my parents dont trust me with theres and they dont care about the fact that you can set up a password/.... PLEASE SOMEONE HELP I WILL BE SO GRATEFUL... And i would really like to get the iphone 4 but if there is no way of etting apps without your credit number then i would have to get a samsung galaxy s3 maybe ...

    You can set up an Apple ID without a credit card.
    Create iTunes Store account without credit card - Support - Apple - http://support.apple.com/kb/ht2534

  • My homepage will load about 30% and then i'm dead in the water. when i close firefox it appears to close but when i try to reopen it tells me that it's already running. started with beta 6 i deleated and loaded ver 5 no change

    when i start firefox, everything starts normal then my homepage (igoogle) starts to load, gets to about 30% and stops. from there i can click on links or bookmark and a new tab will open but no page will load. i can't get anywhere. then when i close firefox it appears to close normally but when i try to reopen firefox i get a message that firefox is still running but not responding and the only way to shut it down is to reboot. when it first occured i was running beta 6 (since it became available, i also used beta 4 & beta 5) i then uninstalled beta 6 and downloaded and installed ver 5 same problem. i then did a system restore to a time before the problem.. no luck. i'm not sure what to try next. IE & chrome both work fine

    I'm in exactly the same boat - dead at blue screen, only option is to salvage using target mode.
    I don't currently have access to another Mac to do target mode. I was planning to buy a new Mac this fall anyway, though. 2 questions in preparation for that purchase:
    1) Is there anything I can do before buying a new Mac to make the salvage process more successful? ie, should I spend the time and money going to the genius bar to have them help me get from totally crippled to partially crippled? (As for expertise, I'm a proficient consumer-grade user, but Apple Support walked me through the safe-boot process, etc.)
    2) Is Apple going to provide 10.5 once it is released to people who buy a new Mac in these 6 weeks pre-release?
    Thanks for your help,
    Bailey

  • Firefox will open 4 or 5 tabs fine, but then will not load any further websites after those first 4 or 5, or allow you to refresh one of those first tabs -- including about:config and the addon page

    Firefox 5 worked fine. I installed Firefox 7, and when I ran it, tabs would just say "connecting to..." and hang. Restarting did not help. Websites open fine in IE and Chrome. Disabled all firewalls and antivirus, did not help. Uninstalled and reinstalled Firefox 5, everything worked fine again. This was using Vista 64-bit.
    Upgraded to Windows 7, uninstalled Firefox 5, installed Firefox 7, had same problem. Uninstalled Firefox 7 completely (including the profile information, I saved that information in another folder), restarted computer, and installed Firefox 7 using a completely clean profile. Did not install any add-ons, checked to make sure all plug-ins were up-to-date, and updated plugins.
    Now when I start Firefox, I can load 3 or 4 or 5 tabs fine -- after those first few tabs are open, I cannot open or refresh any other tabs -- including about:config and the add-on manager -- I have to restart Firefox. The hangup doesn't appear to be related to what websites I am attempting to open, but it looks like the number is the problem. I have run through all of the FAQ procedures, including changing the max number of network connections to 48, and the problem does not seem to go away.
    As a side note, I had this same problem when I tried to go from version 5 to version 6 as well. Version 5 is the most recent version that worked on my system.

    Can you try Aurora - download it from http://www.mozilla.org/en-US/firefox/channel/
    And let us know how it works.

  • Each time I open my computer, I get a full screen about Firefox and a toolbar that needs a yes or no answer. How do I get rid of this?

    I used to be able to press 1 button to get to my Google Home page, but now that I have downloaded the latest version of Mozilla Firefox, the "home page" is now information about Firefox and at the top of my computer, there is a question about security that needs me to say 'no' each time. I do not want to go through these steps every time I start my system.

    See these articles for some suggestions:
    *https://support.mozilla.org/kb/Firefox+has+just+updated+tab+shows+each+time+you+start+Firefox
    *https://support.mozilla.org/kb/How+to+set+the+home+page - Firefox supports multiple home pages separated by '|' symbols
    *http://kb.mozillazine.org/Preferences_not_saved

  • I'm trying to update my itunes to 10.5.2 but it freezes on about 55% and i can't sync my iphone 4s untill i updates... PLEASE HELP!

    i'm trying to update my itunes to 10.5.2 but it freezes on about 55% and i can't sync my iphone 4s untill i updates... PLEASE HELP!

    Have you disabled your virus protection?

  • My iphone 4 is dead after I updated to ios 6.1.3 it doesnt turn on and doesnt respond to itunes also. Visited Apptronix service desk but they say there is nothing they can do about it, and they have charged INR 10640 for a new one. Is there anybody same..

    My iphone 4 is dead after I updated to ios 6.1.3 it doesnt turn on and doesnt respond to itunes also. Visited Apptronix service desk but they say there is nothing they can do about it, and they have charged INR 10640 for a new one. Is there anybody with similar problem....

    Hm... Try this----> http://support.apple.com/kb/ht1808 or http://osxdaily.com/2010/12/04/ipad-dfu-mode/

  • Best avenue to file complaints about bill and have them resolved

    I have been a customer since before 2005 and went with Ntelos in November, I called the night I was at Ntelos to ask Verizon what my contract buy outs were and I was given the prices. The representative tried to offer me whatever promotions she could offer (there wasn't many) and I declined service (there she should have took the initiative to ask about disconnecting). Since my bf opted to keep his number his phone disconnected automatically. I was told my Verizon phone would cycle off within 24 - 48 hours by the Ntelos rep. That was not the case so I called verizon to ensure my phone would disconnect and they told it would at the end of the billing cycle (december 20) which makes sense. I understand I would be responsible for the November - December. Anyways, December 20th rolls around and mind you I've called already to ensure it will take place and it doesn't. I phone in and come to find out the person who took my orders didn't complete the disconnection and now I have to wait until January 20th for it to cycle off and I can finally pay my bill! Well get this in my November - December bill they've charged me $51 for Monthly access (I have a work discount) and $49.99 for insurance and smartphone access for 12/21 - 1/20 and won't refund my $51 as they say that I called out on the phone. I turned the phone on and had voicemails that I think I checked around the time period that they are mentioning (1 day) and that data was used (1 day) I had no outbound calls after December 11th my birthday. Because there are no comments in my account (that I specifically asked them to make) my phone should have been disconnected when I had called in the first of December... really!?! The phone should have been turned off regardless and it was one day out of 30 seriously? I mean the phone has been turned off this whole time and literally only checked to make sure Verizon did their job. I CAN'T HELP IT YOU DON'T KNOW HOW TO DO YOUR JOB, I PUT THE EFFORT IN MULTIPLE TIMES TO LET YOU KNOW MY PHONE NEEDED TO BE DISCONNECTED YOU SHOULD HAVE KEPT RECORD OF IT!!! What really heats me up is that I was told a supervisor would give me a call back after they got out of a meeting and I have not rec'd a call back yet. VERIZON Reps/Supervisors your customers are the reason why you have get a paycheck, I suggest you start treating them a little better. You can't seriously tell me giving me back my $51 for service I DID NOT USE (except according to you for one day you can't even give me details about?) is really going to hurt your pockets. I've been jerked around by your reps for the last 2 months as one told me my contracts were up in January and I shouldn't' be charged for disconnection fees at all, she credited me those termination fees but they later got rejected (after she said her supervisor approved while I was on hold) and NO ONE HAD THE COURTESY TO NOTIFY ME!
    I've worked in customer service before and I'll be first to tell you that your reps are not trained very well and you have horrible ethic! You should not charge your customers for an error that was your fault; especially since it was your reps that I asked specifically to note my account and didn't (this isn't my first rodeo with you all, it should be standard procedure to give your reps time to comment before throwing them into another phone call). I'm not doing this for my health here, that $51 could buy diapers and baby food for my daughter and you are crazy if you think I'm going to let it slip through my fingers to line your pockets. I will keep escalating it until you do something about it and I don't care that you already gave me an inconvenience credit I deserve that and my $51 so don't try to justify it that way! This has been way more than an inconvenience, so don't worry I'll inconvenience you as well!
    >> Edited to comply with the Verizon Wireless Terms of Service <<
    Message was edited by: Verizon Moderator

    With my new provider I am only using the chat function to settle anything with them so I can save the conversations I've had with them (not that I've had any issues thus far). It should be standard procedure for them to comment your account while they are on the phone with you before hanging up. I should have been annoying and asked them to read back their comments (hindsight ugh!).  I'm sorry that you are having to deal with this as well, just know you are not the only one receiving horrible customer service. I'll share with you what I wrote on their Facebook page. They really should take some accountability for their actions and have better follow up on resolving issues (or train their representatives better). I can't stand having to talk to another person time and time again explaining the same thing i just explained to 3 people before them.
    Almost immediately, I received some attention after posting this:
    Dear Verizon,
    I am appalled, especially after reading your credo, that you are refusing to credit back money that is owed to me because your representatives didn't take the necessary time that they should have to comment (after I specifically asked) in my account after I diligently called in multiple times to ensure that my disconnection took place when it was scheduled to and was told that it would (an ongoing issue since the beginning of December). Come to find out that the representatives I spoke with prior to December 20th didn't do their jobs correctly by not entering the disconnection orders in. "Verizon Credo- a set of principles that describes our culture of integrity, respect, performance excellence and accountability. The Credo is a blueprint that directs us to live up to the highest standards possible when serving our customers, shareowners, communities and each other." Let me school you on something here because it appears that you just put that mission statement up on your website 'cause it sounds good, you certainly do not follow through! Accountability: Noun - the quality or state of being accountable; especially an obligation or willingness to accept responsibility or to account for one's actions (i.e. public officials lacking accountability). It doesn't matter that you cannot find any proof in my statements it doesn't change the fact that it happened and I am not a liar. I seriously wouldn't exhaust this must effort had I been lying. I'll take this a step further and reference your statement "we focus outward on the customer, not inward. We make it easy for customers to do business with us, by listening, anticipating and responding to their needs." First of all, when I made my initial call to you all asking what my contract buyout prices were and your rep tried to offer me promotions (or lack there of) to keep me as a customer and I declined she should have "anticipated" my need for disconnection. I shouldn't have had to jump through so many hoops to get my service disconnected from you all and pay my final bill. It's not my fault that your representatives weren't trained well enough to correctly put through disconnection orders. Based on my interactions with your customer service I could see where people would disconnect their services regularly!!!!! You are not making it easy for me to severe ties with you and conduct BUSINESS and you are not responding to my NEEDS. I think you forget that I could be a potential customer in the future. If it's one thing I learned from my Communications Degree is that negative feedback will reach more consumers vs. positive feedback of a company and how they handle their business. I have 1,000 plus facebook friends and twitter followers so I'm pretty sure my negative experience could reach quite a few people! You say you have integrity? How is it moral uprightness to charge me for a whole month of service (regardless if the phone was turned on once) for a billing period that shouldn't have existed if your customer service reps did their job correctly? I suggest that you all take a good look at the way you are treating your current customers because we are the reason you get a paycheck! You should make your customers a priority especially if they've been with you for 10 + years regardless if they are disconnecting service or not! How about following through, taking ACCOUNTABILITY and having that supervisor representative call me back from my phone conversation last night like I am a priority (how every customer should be treated) and helping me get the money that I am owed, regardless if the phone had been turned on for a short period (your rep couldn't even tell me what numbers I supposedly called - exactly the phone has been off since December 20th if not before unless turned on to confirm disconnection)! Oh but let me guess did you all forget to put that in my account comments as well? Probably like there is no mention of the formal complaint I filed against some of your representatives that there was supposedly no ticket number for. I thought I was going to regret leaving Verizon for another provider but it turns out that I only wish I would have left sooner and actually gone to a authorized dealer/ Verizon Store to process my disconnection because your customer service line is a joke!

  • We have always used one iTunes account and I want to crate a new account for my daughter.  What is the best way to go about this and will she need to download free apps again?

    We have always used one iTunes account and I want to crate a new account for my daughter.  What is the best way to go about this and will she need to download free apps again?

    Not going to happen the way you want it to.
    When you add a gift card balance to the Apple ID, it's available for the Apple ID.
    Probably best to create unique Apple ID's for each... this will also make things easier in the future as purchases are eternally tied to the Apple ID they were purchased with.

  • Hi,  I've just purchased and installed an upgrade from Lightroom 4 to 5.  It doesn't seem to handle raw files authored with a new Nikon D750 camera.  I spoke to the sales rep about this and he gave me a link to the 8.6 DNG converter page with instructions

    Hi,  I've just purchased and installed an upgrade from Lightroom 4 to 5.  It doesn't seem to handle raw files authored with a new Nikon D750 camera.  I spoke to the sales rep about this and he gave me a link to the 8.6 DNG converter page with instructions to download.  8.6 only works with Mac OS 10.7-10.9, according to the page.  I'm running Yosemite, Mac 10.10.  Please can you tell me my options?  Lightroom 4 worked beautifully with my older cameras' raw files so I would like to continue using the application.  What should I do?  How soon will Lightroom 5 be able to deal with raw files from a D750.  Many thanks, Adam.

    Until the next version of Lightroom is released, you need to use the DNG Converter version 8.7RC to convert your RAW photos to DNG and then import the DNGs into Lightroom.

  • Can anyone offer some advice i am looking to upgrade the OS system on one of my macbook pro's, currently running os10.4.11, I would like to upgrade to OS10.5? how would I go about this, and is there a cost, for what is an old operating system now?

    Can anyone offer some advice i am looking to upgrade the OS system on one of my macbook pro's, currently running os10.4.11, I would like to upgrade to OS10.5? how would I go about this, and is there a cost, for what is an old operating system now?

    Since your Mac probably came with 10.4, there is no longer a way to get 10.5 Leopard install media. IF it has the requirements, you may be able to upgrade to 10.6 Snow Leopard by buying the boxed install media at the Apple Store for $30.
    System requirements are found here: http://support.apple.com/kb/SP575
    General support can be found here: http://www.apple.com/support/snowleopard/

Maybe you are looking for

  • Tapping no longer works after installing Windows 7 RC using boot camp.

    After installing it i found that tapping to click no longer works in either OS X or Windows. I've checked system preferences and it is still ticked and all other gestures work except double tap and single tap. How do i fix this?

  • Access denied to external Hard Drive on Windows 7?

    Hey, Thanks in Advance for your help. Yesterday I downloaded and installed Windows 7 (which looks like its going to be a massive improvement on Vista!!). Though I had a problem when I tried to open my external Hard drive (which is an Internal hard dr

  • Why the difference in free space on internal drive?

    I'm confused - when I look at my Storage info under the "About This Mac" item, my internal drive shows that it has "141.6 GB free out of 499.25 GB" (and why it shows 87.54 GB of Backups, I don't know). Yet when I look at a Finder window, the drive sh

  • I am listed as an Account Member, even though I'm the only one on the account.

    How can I upgrade myself to Account Owner or Manager when it says the request needs to be approved by the Account Owner, and there is no Account Owner? What gives?

  • External HD "Beeping"

    I have a 120GB external HD I just connected to my power book G4 (USB) The drive light comes on and then it starts beeping and is not recognized as a new device. The drive has documents and pictures, no software. The drive content was recently downloa