Is there any way to access an overridden method of super class?
class Animals
void makeNoice(){System.out.println("General noice");}
class Dog extends Animals
void makeNoice(){System.out.println("bark");}
};Is there any way to access the makeNoice() of Animals class from a Dog object
Dog dog = new Dog();
Animal animaldog = dog;
animaldog.makeNoice(); // will always calls Dog's makeNoice() ie the overriden method.
Is there a way to access the Animals makeNoice() method ? by using cast or super etc?
Or it is not possible at all?
Rajeebs wrote:
Now another question coming in my mind.
Whether any way to access a method which belong to super class's super class without using any method of class B,
like super.super.fn() ??Isn't this just the same question again? And won't you again just "solve" it by writing some invokeSuperSuperMethod or other? This flawed design is quickly getting out of hand, isn't it? The question isn't "How can I invoke an arbitrarily deep superclass' method?" but more "Why do I need to invoke a method belonging to a concrete type at all?". If you need to do that, chances are you've misused inheritance.
To use your initial sample code, in what circumstance would you require that a Dog make anything other than a Dog noise? It makes no sense. Point is, you have an Animal abstraction, and can call makeNoise on any instance of any subclass, and it will make the appropriate noise. By trying to use trickery to force other noises, you're doing something unnatural, and you're also depending on actual specific concrete subclasses. If you're going to go to specific classes and ask them to make their noise, what use is the inheritance? What use it the polymorphism?
Are we heading into another "I've got a brilliant idea for a [useless language feature|http://forums.sun.com/thread.jspa?threadID=5423706&messageID=10905772#10905772], guys!" thread?
Similar Messages
-
Is there any way to access files from the Classic environment to my iMac running on Leopard (10.5.8)?
Sorry, no.
-
Is there any way to access a PDF in iCloud on an iOS device?
After a PDF has been saved in iCloud, is there any way to access it from an iOS device (iPad)?
No, you can only view it from a Mac that is signed into your account.
-
Hi,
I had my iphone stolen a few weeks ago which had quite a lot of music on that I had downloaded from itunes via my phone but had not synced with itunes on my computer.
Is there any way to access the music now or is it lost? Thanks xBy any chance, did you have the Find My iPhone app installed prior to it being stolen?
Reporting a lost or stolen Apple product
Hopefully you had your iTunes purchases backed up to an external source such as an external drive or CD's? -
Is there any way to access the thumbails-db, where finder stores its icons that are assigned to files?
Thats a SQLite-DB? Is it possible to access and export them? I´d like to use that Db to assign thumbs to files on my NAS.
Thx!Are the thumbnails & icons stored in the .DS_Store-File?
When visible, how can I access the content stored in that file? -
Is there any way to access my old my Verizon account to retrieve old text messages from my own old account from 8 months ago? I am getting a divorce and I need info off of that account for my hearing to prove what he did.
What do you mean by "when I brought the messages up back in March"?
Were the messages on your phone? Simply because messages are on your phone does not mean they are still on Verizon's servers. You use internal phone memory to store messages on your phone. The messages do not stay on Verizon's servers until you delete them from your phone.
On the other hand, if you still have your phone and have not reset it since you stopped using it, the texts may still be on your phone. Good luck. -
Is there any way to access the Pages app templetes that were there six months ago? The one I used for my recipes is no longer there.
What was the name of the recipe template?
Or was it one you created yourself.
It helps when you tell us that you upgraded both your OS and Pages, which it appears you have done.
Possibly even changing your Mac or iOS device. Which is it btw?
Probably you have a new Pages which has only a fraction of the templates, because it has a fraction of the features.
Peter -
I have an iMac G5 with OSX 10.5.8 that does not recognize my Western Digital external drive. I had no problems with this until I upgraded to 10.5. Most of my music library is stored on the external drive. Is there any way to access it to recover the music?
How is it connected? Have you tried different port? How about logging in as a different user then trying to mount the drive.
-
my old computer died and I got just got a new one. Is there any way to access the movies, apps, etc. that I bought on i tunes from the new computer?
Yes....
On the new computer, launch iTunes. From the menu bar click click Store / Authorize This Computer.
Then re download your iTunes purchases.
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
Is there any way to access my contacts from a non apple device?
Is there any way to access my contacts from a non apple device?
I am waiting on my new phone to arrive but in the mean time can I access my contacts from a non apple device? Please help!If you synced them to iCloud, you can view them on icloud.com from your computer. They can also be accessed from an Android device using SmoothSync for Cloud Contacts. Or, you can download them from iCloud as a vCard (see http://support.apple.com/kb/PH3606), then import them to another service such as Google in order to sync them with a non-Apple device.
-
Is there any way to access the superclass' superclass' constructor?
Hi,
Is there any way to access the superclass' superclass' constructor?
e.g.
class A {...}
class B extends A {...}
class C extends B {
public C() {
// can I do something like super.super();
// I mean then doesn't work, but is there anything similar?
}In the OP you don't need to call "super.super()" since the A class no-args constructor will be invoked anyway.
You can, however, invoke constructors using reflection. For example:
public class A {
public A() {
System.out.println("A()!");
public A(int i) {
System.out.println("A(int i)! : " + i);
public class B extends A {
public B() {
System.out.println("B()!");
public class C extends B {
public C() throws Exception {
Class types[] = new Class[1];
types[0] = Integer.TYPE;
Object args[] = new Object[1];
args[0] = new Integer(1);
this.getClass().getSuperclass().getSuperclass().getConstructor(types).newInstance(args);
System.out.println("C()!");
public static void main(String[] args) throws Exception {
new C();
}Will print:
A()!
B()!
A(int i)! : 1
C()!
btw: DON'T use this code! It's just to show you that it's possible. -
My iphone was recently stolen. Is there any way to access my purchases in itunes (without having transferred them to a computer)? Any help would be appreciated. Thanks!
Hm, good suggestion, but I've actually already done this (and I've had a friend go through the steps with me). There is just NOTHING that is showing up under any of the categories in the cloud for downloading. The thing is, I'm just not sure if I enabled cloud-sharing or not on my iphone (although I know I've backed up my data through cloud on my iphone at some point).
Any other suggestions? -
Is there any way to access my music in Itunes without a laptop or computer?
is there any way to access my music in Itunes without a laptop or computer?
Well, where is your iTunes stored?
-
Is there any way to access the App Store using OS10.4.11 on a Mac G4?
Hi All:
Is there any way to access the App Store using OS10.4.11 on a Mac G4 (dual 1.42 Ghz, FW800, MDD)?
Thanks,
RobertNo. None of the applications from it will work either.
(81546) -
Is there any way to access phone settings programatically?
I want to access some phone settings in my app. Or is there any way to open phone settings from my app.
Hi, Thanks for the reply.
But what about using some third party API in the code, like InAppSettingsKit, http://www.inappsettingskit.com/..will it affect Apple Store verification process?
Even if it is passed and accepted by Store will these affect the application behavior later?
Maybe you are looking for
-
I have an iPad and an iPhone that share an iCloud account. I didn't realize when I got my iPad last year that when I signed up the iCloud on the device that it would share and use 5g of iCloud between the both of them. How do I unsync them and have t
-
Question about USB power adapter
hey guys, i have a question, i have an USB power adapter as a charger for my itouch and I accidentally dropped the USB power adapter on the floor. would it get damage? and if it's damage, would it be advisable to charge my itouch using it? would it d
-
Accidentally erased Contacts on iPhone: syncing problem
I accidently synced my iPhone to a new laptop with no Contacts. This erased all Contacts from iPhone. With TM, I restored Contacts to new MBPro. How do I sync so that all Contacts come to iPhone rather than iPhone erasing MBPro Contacts?
-
Log Miner is finding DDL for "new" tables, but also DML for "older" tables.
oracle 10.2.0.5.0 Standard Edition (at some point in the past it was "downgraded" from enterprise edition). It's making me crazy, i create a table then insert/update rows. Log miner only shows me the create. However, if i do insert/update on an "ol
-
Okay, I think this isn't supposed to be in this forum (Seeing as how there's a JDBC forum and all..), but this is so basic and I'm kicking myself over it I thought I'd put it in here. Anyways: I just installed mysql-connector-java-2.0.14, or at least