Quick question about inheritance and exceptions

If I have two classes like this:
public class ClassA {
    public void myMethod() throws NumberFormatException {
      throw new NumberFormatException();
public class ClassB extends ClassA {
    public void myMethod() {
}Does myMethod() in classA override myMethod in classB?
And why?
Thank you,
V

I just want to add that since NumberFormatException is
a descendant of RuntimeException, you are not required
to declare that the method throws this exception. Some
people think it is a good idea to declare it anyway
for clarity. Personally, I don't think so.I agree.
I think Sun recommends that you don't declare unchecked exceptions in the method declaration, but do document them in the javadoc comments.

Similar Messages

  • A question about inheritance and overwriting

    Hello,
    My question is a bit complicated, so let's first explain the situation with a little pseudo code:
    class A {...}
    class B extends A{...}
    class C extends B {...}
    class D extends C {...}
    class E extends B {...}
    class F {
      ArrayList objects; // contains only objects of classes A to E
      void updateObjects() {
        for(int i = 0; i < objects.size(); i++)
          A object = (A) objects.get(i); // A as superclass
         update(A);
      void update(A object) { ... }
      void update(B object) { ... }
      void update(D object) { ... }
    }My question now:
    For all objects in the objects list the update(? object) method is called. Is it now called with parameter class A each time because the object was casted to A before, or is Java looking for the best fitting routine depending on the objects real class?
    Regards,
    Kai

    Why extends is evil
    Improve your code by replacing concrete base classes with interfaces
    Summary
    Most good designers avoid implementation inheritance (the extends relationship) like the plague. As much as 80 percent of your code should be written entirely in terms of interfaces, not concrete base classes. The Gang of Four Design Patterns book, in fact, is largely about how to replace implementation inheritance with interface inheritance. This article describes why designers have such odd beliefs. (2,300 words; August 1, 2003)
    By Allen Holub
    http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html
    Reveal the magic behind subtype polymorphism
    Behold polymorphism from a type-oriented point of view
    http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph_p.html
    Summary
    Java developers all too often associate the term polymorphism with an object's ability to magically execute correct method behavior at appropriate points in a program. That behavior is usually associated with overriding inherited class method implementations. However, a careful examination of polymorphism demystifies the magic and reveals that polymorphic behavior is best understood in terms of type, rather than as dependent on overriding implementation inheritance. That understanding allows developers to fully take advantage of polymorphism. (3,600 words) By Wm. Paul Rogers
    multiple inheritance and interfaces
    http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
    http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html
    http://www.artima.com/intv/abcs.html
    http://www.artima.com/designtechniques/interfaces.html
    http://www.javaworld.com/javaqa/2001-03/02-qa-0323-diamond_p.html
    http://csis.pace.edu/~bergin/patterns/multipleinheritance.html
    http://www.cs.rice.edu/~cork/teachjava/2002/notes/current/node48.html
    http://www.cyberdyne-object-sys.com/oofaq2/DynInh.htm
    http://www.gotw.ca/gotw/037.htm
    http://www.javajunkies.org/index.pl?lastnode_id=2826&node_id=2842
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=001588
    http://pbl.cc.gatech.edu/cs170/75
    Downcasting and run-time
    http://www.codeguru.com/java/tij/tij0083.shtml
    type identification
    Since you lose the specific type information via an upcast (moving up the inheritance hierarchy), it makes sense that to retrieve the type information ? that is, to move back down the inheritance hierarchy ? you use a downcast. However, you know an upcast is always safe; the base class cannot have a bigger interface than the derived class, therefore every message you send through the base class interface is guaranteed to be accepted. But with a downcast, you don?t really know that a shape (for example) is actually a circle. It could instead be a triangle or square or some other type.
    To solve this problem there must be some way to guarantee that a downcast is correct, so you won?t accidentally cast to the wrong type and then send a message that the object can?t accept. This would be quite unsafe.
    In some languages (like C++) you must perform a special operation in order to get a type-safe downcast, but in Java every cast is checked! So even though it looks like you?re just performing an ordinary parenthesized cast, at run time this cast is checked to ensure that it is in fact the type you think it is. If it isn?t, you get a ClassCastException. This act of checking types at run time is called run-time type identification (RTTI). The following example demonstrates the behavior of RTTI:
    //: RTTI.java
    // Downcasting & Run-Time Type
    // Identification (RTTI)
    import java.util.*;
    class Useful {
    public void f() {}
    public void g() {}
    class MoreUseful extends Useful {
    public void f() {}
    public void g() {}
    public void u() {}
    public void v() {}
    public void w() {}
    public class RTTI {
    public static void main(String[] args) {
    Useful[] x = {
    new Useful(),
    new MoreUseful()
    x[0].f();
    x[1].g();
    // Compile-time: method not found in Useful:
    //! x[1].u();
    ((MoreUseful)x[1]).u(); // Downcast/RTTI
    ((MoreUseful)x[0]).u(); // Exception thrown
    } ///:~
    As in the diagram, MoreUseful extends the interface of Useful. But since it?s inherited, it can also be upcast to a Useful. You can see this happening in the initialization of the array x in main( ). Since both objects in the array are of class Useful, you can send the f( ) and g( ) methods to both, and if you try to call u( ) (which exists only in MoreUseful) you?ll get a compile-time error message.
    If you want to access the extended interface of a MoreUseful object, you can try to downcast. If it?s the correct type, it will be successful. Otherwise, you?ll get a ClassCastException. You don?t need to write any special code for this exception, since it indicates a programmer error that could happen anywhere in a program.
    There?s more to RTTI than a simple cast. For example, there?s a way to see what type you?re dealing with before you try to downcast it. All of Chapter 11 is devoted to the study of different aspects of Java run-time type identification.
    One common principle used to determine when inheritence is being applied correctly is the Liskov Substitution Principle (LSP). This states that an instance of a subclass should be substitutible for an instance of the base class in all circumstances. If not, then it is generally inappropriate to use inheritence - or at least not without properly re-distributing responsibilities across your classes.
    Another common mistake with inheritence are definitions like Employee and Customer as subclasses of People (or whatever). In these cases, it is generally better to employ the Party-Roll pattern where a Person and an Organization or types of Party and a party can be associated with other entities via separate Role classes of which Employee and Customer are two examples.

  • Quick Question About Ringtones and iPhone

    I've looked through the discussions and could not find my answer. If you know of a discussion already posted please refer me to that.
    Question: After buying a song from iTunes is there a statute of limitations governing the song's ability to create a ringtone?
    None of the songs that I bought before my iPhone can be made into ringtones and songs that I bought a few days ago, which initially I could make into a ringtone, but did not, now can no longer be made into a ringtone.
    Also, is there any program besides iTunes that can be used to create ringtones from any song?
    Thank you for any and all help.
    Message was edited by: Abe

    No there is not a time limit that I know of. The bell has disappeared on mine too. Have you clicked Store>create ringtone?
    There are many, many posts about other ways to make ringtones:
    http://discussions.apple.com/thread.jspa?messageID=8256727&#8256727
    http://discussions.apple.com/thread.jspa?messageID=8598523&#8598523
    http://discussions.apple.com/thread.jspa?messageID=8682828&#8682828
    http://discussions.apple.com/thread.jspa?messageID=8613825&#8613825
    http://discussions.apple.com/thread.jspa?messageID=8570952&#8570952
    http://discussions.apple.com/thread.jspa?messageID=8631324&#8631324
    These are just the first page of many in a forum search.

  • Question about inheritance and  casting

    according to the java api it said Calendar() is a super-class of GregorianCalendar(). with that said it means GC inherits all members of C(). i hope everyone agrees with me here.
    why is it necessary to do this:
    Calendar c = new GregorianCalendar();//by the way this is called implicit casting per the java tutorial.if GC inherits everything from C, and if you need members from both classes, then wouldn't it be enough to just do
    GregorianCalendar gc = new GregorianCalendar();why is it necessary to declare a variable of the parent class and assign a subclass reference to that variable?

    then why does the tutorial show this?Why not? It's legal Java. It's what I would probably write, unless I knew I was going to use some methods that were in GregorianCalendar and not in Calendar.

  • Quick question about rendering and exporting with multiple presets

    Probably a very simple question but I'm pretty new to PPro, so I'd appreciate your help...
    I've got an uncompressed AVI video that I want to export to mp4 using several presets (that means several exports). What I intend to do is the following:
    I create a sequence and put my AVI file in there and then I just apply the preset and without rendering go to export media, select my export setting, and put it in the encoding queue at the Media Encoder. Then on the same sequence, I clear the preset and apply a new one, and again without rendering, go to export and then to the encoding queue. I repeat this for as many times as presets as I want to apply. At the end I have created (in no more than 2-3 minutes) several exports in the Adobe Media Encoder queue, that I can launch and go and do something else while encoding...
    My question: will the export files each have the different preset applied even though it was not rendered? if it does not work, would that work if I were to do this with each preset applied on a different sequence, even without rendering?
    Thanks in advance for your input!

    I create a sequence and put my AVI file in there and then I just apply the preset.
    Then on the same sequence, I clear the preset and apply a new one, and again without rendering, go to export and then to the encoding queue.
    Does "apply the preset" mean selecting an encoding preset
    before sending the Sequence to the Queue?
    If I understand what you are trying to do...
    It sounds like you want to do multiple, different format
    exports from the same Premiere Sequence.
    If so...
    I would Queue the Sequence to Media Encoder once from Premiere,
    then duplicate the entry in the Queue (Ctrl+D) and assign the
    different encode types to the duplicates in Media Encoder,
    (instead of Queueing the Sequence multiple times).
    ...will the export files each have the different preset applied even though it was not rendered?
    A Sequence will be encoded using the assigned settings.
    You can set multiple encodes in the Queue, each with different settings.
    I'm not sure what you mean by "even though it was not rendered...".
    Unless you have specified 'Use Preview Files' in your encoding,
    it will make no difference if your Sequence is 'Timeline Preview'
    rendered or not.

  • Quick question about MPE and GPU configuration.

    I have 2 graphics card in my mac pro. I am trying to use one to drive the displays and dedicate the other solely to PPro MPE. My question is do i have to connect a display to the GPU to enable MPE?

    Damn! I had a feeling it was like that. So in a dual monitor setup if I have a CUDA enabled card driving one display and a non cuda card driving the other will MPE work if i put just the program monitor in it and keep the rest in the other(non-CUDA) monitor?

  • Quick Question about Authorisation and FMS

    Hi,
    Can someone tell me if it's possible configure FMS 3.5 so that it authenticates against Webseal so that only authorised users can have access to the media?
    Thanks

    Does the normal version of FMS support cookie passing? We have Webseal infront of FMS and it seems that our flash player doesn't always pass the authorisation cookie through.
    Also could you expand more on the use of  LoadVars, XML send/load, NetServices, or XMLSockets to communicate with Webseal?
    Many Thanks

  • New iPod owner - Quick question about iTunes and iPod

    Hey everyone. I just bought the new 5.5G black 30GB.
    I have a lot of untagged MP3s, but my boyfriend tagged most of them. After I overwrite the untagged files (but with the same filename) with the tagged files, now that I have all of my music on iTunes and on my iPod, how do I get iTunes to do a mass refresh and see all the tags, so it can show them properly and update the iPod accordingly?
    Also, my new ipod keeps crashing! It keeps freezing when I hit the skip button or try to do something when it's loading a video or a song. It just seems really unstable. Any help is much appreciated. Thanks!

    oh sorry i misunderstood you
    this is from i-tunes help - is this any good
    Song titles look scrambled after importing from another application
    If a song's title and information don't appear correctly, the file was probably created using a program that stores information in a different way from iTunes. You may be able to resolve the problem by reversing the Unicode characters in the song tags.
    To reverse the Unicode characters:
    Select the song and choose Advanced > Convert ID3 Tags.
    To select multiple adjacent songs, press the Shift key while you click the song titles. To select multiple songs that are not adjacent, press the Control key and click.
    Click Reverse Unicode.
    To change the information back to what you had before, choose Reverse Unicode again.

  • Quick question about Photoshop and Bridge

    If someone purchases the Standard Photoshop software, does Bridge come with it? I think it does, but I am not sure.

     

  • Quick question about AppleScript and "current playlist."

    I have a few scrips that I'd like to have operate on whatever playlist is selected at the moment. The script dictionary has a "current playlist" object for iTunes, but it references the playlist the currently playing song is in, not the currently selected playlist. This is not what I want.
    I suppose I could make iTunes play, pause, then stop in my script, but it seems like there has to be an easier way. Suggestions?

    Hi,
    Someone in the Applescript Forum might be able to help:
    http://discussions.apple.com/forum.jspa?forumID=724
    Regards,
    Colin R.

  • A quick question about WebDynpro SLD and R/3 with concurrent users

    Hello ,
    I have a very quick question about Webdynpros and SLD connecting to an R/3 system, when you configure a webdynpro to connect to an R/3 system using SLD, you configure a user name and password from the R/3  for the SLD to use. What I would like to know is when I have concurrent users of my webdynpro, how can I know what one user did in R/3 and what another user did? Is there a way for the users of the web dynpro to use their R/3 credentials so SLD can access the R/3? Like dynamically configuring the SLD for each user?
    - I would like to avoid leaving their their passwords open in the code ( configuring two variable to get the users username and password and use these variables as JCO username and password )
    Thanks Ubergeeks,
    Guy

    Hi Guy
    You will have to use Single Sign On to achieve this. In the destination you have defined to connect to R/3 , there is an option to 'useSSO' instead of userid and password. This will ensure that calls to R/3 will be with the userid that has logged into WAS. You wont need to pass any passwords because  a login ticket is generated from WAS and passed on to R/3. The userid is derived from this ticket.
    For this to happen you will have to maintain a trust relation ship between R/3 and your WAS ,there is detailed documentation of this in help files. Configuration is very straight forward and is easy to perform
    Regards
    Pran

  • A question about grub and USB

    Hi All
    I have a quick question about grub and USB that I can't quite find the answer to by searching.   Most of the FAQs discuss booting a full linux dristribution from USB. My situation is this.  I am getting a new computer with two drives, the second will be arch and the first will be Vista (for my wife).  I want the computer to boot the same way that my wife's machine boots at work so I don't want to install grub on the MBR.  So, is there a way to have all of the grub config files and kernels installed on the second drive and simply install to grub boot loader to the MBR of a USB stick?  My goal would be to simply plug the USB stick into the new PC and boot arch from the second drive. 
    Thanks
    Kev

    i cant say for hp's
    havent worked on any in a while
    recent machines have been coupleof dell's , vaio & emachine
    which dells do offer it at least the ones i tried , my laptop does(dell)
    all home pc's are built by me which do offer to boot individual drives
    what hp you getting it may tell in specs
    are both discs sata? if so it might not offer this option with 2 drives of same interface
    check your power supply alot of these preconfigured machines put cheap under reated power supplies in there
    & will burn your motherboard i just replaced PS(250 watt) & mobo(845gvsr) in an emachines <cheap stuff<
    i hope you researched the pc before buying ie : mobo, power supply are the biggest concerns
    i find it much more benificial to build my own machine gives me peace at mind. the cost is sometimes more in $ but not always , your biggest expense is time researching hardware
    if you live in usa the best places to start looking are bensbargains.net & pricewatch.com
    i am not affiliated with either & niether sell the hardware they are just advertisers a place to buy
    for costomized machines that i would trust is unitedmicro.com theyll asemble & test before shipping
    i have gotten 2 machines so far from them with NO PROBLEMS with hardware (knock knock)
    you may want to consider this in your next venture for pc

  • One very basic question about inheritance

    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????

    SumitThokal wrote:
    One very basic question about inheritance.
    Why we need inheritance?
    the benefit of inheritance also achieve by creating instance of base class using it in other class instead of extending the base class.
    Can any one please explain why we are using inheritance instead of creating object of base class????What did you find out when you looked on Google?
    One example of inheritance comes in the form of a vehicle. Each vehicle has similarities however they differ in their own retrospect. A car is not a bus, a bus is not a truck, and a truck is not a motorbike. If you can define the similarities between these vehicles then you have a class in which you can extend into either of the previous mentioned vehicles. Resulting in a reusable class, dramatically reduces the size of code, creates a single point of definition, increases maintainability, you name it.
    In short there are thousands of benefits from using inheritance, listing the benefits could take a while. A quick Google search should give you a few hundred k if not million links to read.
    Mel

  • Hi, I have quick question about use of USEBEAN tag in SP2. When I specify a scope of SESSION for the java bean, it does not keep the values that I set for variable in the bean persistent.Thanks,Sonny

     

    Make sure that your bean is implementing the serializable interface and that
    you are accessing the bean from the session with the same name.
    Bryan
    "Sandeep Suri" <[email protected]> wrote in message
    news:[email protected]..
    Hi, I have quick question about use of USEBEAN tag in SP2. When I
    specify a scope of SESSION for the java bean, it does not keep the
    values that I set for variable in the bean persistent.Thanks,Sonny
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • Three questions about Java and Ftp

    Hello, i've the following questions about Java and Ftp:
    1- .netrc file is in $HOME directory but i can't access to this directory from java code. The following line producesan Exception (directory doesn't exists)
    FileWriter file = new FileWriter ("$HOME/.netrc");
    2- .netrc file must have the following permissions: -rw- --- --- but when i create the .netrc file the following permissions are on default: -rw- r-- r--, how can i change this permissions? (In java code, i can't use chmod.....)
    3- Are there any way to pass parameters to a .netrc file? If i get to do this i needn't change the permissions because i can't modify or create/destroy this file.
    Thanks in advanced!!!
    Kike

    1- .netrc file is in $HOME directory but i can't
    access to this directory from java code. The
    following line producesan Exception (directory
    doesn't exists)
    FileWriter file = new FileWriter ("$HOME/.netrc");$HOME would have to be replaced by a shell, I don't
    think you can use it as part of a legal path.
    Instead, use System.getProperty("user.home");
    Ok, thanks
    2- .netrc file must have the followingpermissions:
    -rw- --- --- but when i create the .netrc file the
    following permissions are on default: -rw- r--r--,
    how can i change this permissions? (In java code,i
    can't use chmod.....)Yes, you can: Runtime.exec("chmod ...");
    I need to use estrictly the .netrc with -rw- --- --- permissions
    Yes, i can use Runtime.exec ("chmod ..."); but i don't like very much this solution because is a slow solution, am i right?
    3- Are there any way to pass parameters to a.netrc
    file? If i get to do this i needn't change the
    permissions because i can't modify orcreate/destroy
    this file.I don't think so. Why do you need the .netrc file in
    Java at all? Writing a GUI frontend?I want to use automatic ftp in a java program and FTP server, the files and path are not always the same, so i can:
    - modify .netrc (for me is the complex option)
    - destroy and create a new .netrc (is easier but i have permissions problem)
    - use .netrc with parameters but i haven't found any help about it
    Thanks for your prompt reply!!!!
    Kike

Maybe you are looking for

  • How to create a workflow composite with the ability to upload a document in

    Hi, Is there any way to attach/upload a document while creating or modifying a user. I have a requirement where user will create a document(.xls/.csv/.doc) with his details and he needs to upload that document while updating the profile. If he is cre

  • Boot Camp V-2.1 will not install

    Boot Camp installation of upgrade to Version 2.1 will not install. Can anyone help me?

  • Apple software RAID 0 not spinning down while not in use

    I have a G-Tech G-RAID w/ Thunderbolt, 8TB external enclosure.  It has two 4TB fujitsu drives in it, set up as RAID 0 with Apple's Disk Utility v13 (426) that ships with 10.8 Mountain Lion.  This is attached to a very cleanly installed Mid 2011 Mac M

  • Bus fails after upgrade to Logic 9.1.3

    I'm not 100% sure this is related to the upgrade, but I upgraded yesterday and today I've been working on a song that has ~65 tracks and my buses are behaving REALLY strange. 11 drum tracks are fed to a single bus and mixed like that. It has worked b

  • Windows thumbnail for PSD files

    Hi everyone, Until a few days ago, PSD files never did have an icon in Windows Explorer. But now I have this : (I pixelated the file names so this is normal.) What is not normal, or at least, what I don't understand, is how the file thumbnail was cre