Can a Class extend a Main Class

Can a Class extend a Class containing
"public static void main(String[] args)"

What sort of methods a class has doesn't determine
whether it may be extended or not. If the class is
marked Final determines whether it may be subclassed
or not.
And if it is accesible in the context that it is being used in.

Similar Messages

  • How can a class extending MouseAdapter override mouseDragged method?

    I've found this code from somewhere, don't remember where
    private class DragLimiter extends MouseAdapter {
    @Override
    public void mousePressed(MouseEvent e) {
    pressedX = e.getX();
    pressedY = e.getY();
    @Override
    public void mouseDragged(MouseEvent e) {
    label.setLocation(
    Math.min(
    Math.max(label.getX() + e.getX() - pressedX, BORDER),
    panel.getWidth() - label.getWidth() - BORDER),
    Math.min(
    Math.max(label.getY() + e.getY() - pressedY, BORDER),
    panel.getHeight() - label.getHeight() - BORDER));
    }The question is how can a class extending MouseAdapter override mousedragged()?
    I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListener, I think this has something to do with the question.
    But I've always thought you can only override methods of the super classes or interfaces not vice versa.
    I believe I have some kind of fundamental misunderstanding of this and would like to have some help in understanding this.
    Thanks

    This is more a Java question than a Swing question.
    I found that MouseAdapter implements MouseListener whose subinterface is MouseMotionListenerThat's not correct: if you look at MouseAdapter Javadoc, you'll find that it implements both MouseListener and MouseMotionListener (and MouseMotionListener is not a subinterface of MouseListener).
    Regardless, if you look at the javadoc, you see that MouseAdapter declares a method public void mouseDragged(MouseEvent). It doesn't matter whether this is also declared by an interface, a subclass can override it all the same.

  • Why can't classes with private constructors be subclassed?

    Why can't classes with private constructors be subclassed?
    I know specifying a private nullary constructor means you dont want the class to be instantiated or the class is a factory or a singleton pattern. I know the workaround is to just wrap all the methods of the intended superclass, but that just seems less wizardly.
    Example:
    I really, really want to be able to subclass java.util.Arrays, like so:
    package com.tassajara.util;
    import java.util.LinkedList;
    import java.util.List;
    public class Arrays extends java.util.Arrays {
        public static List asList(boolean[] array) {
            List result = new LinkedList();
            for (int i = 0; i < array.length; i++)
                result.add(new Boolean(array));
    return result;
    public static List asList( char[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Character(array[i]));
    return result;
    public static List asList( byte[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Byte(array[i]));
    return result;
    public static List asList( short[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Short(array[i]));
    return result;
    public static List asList( int[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Integer(array[i]));
    return result;
    public static List asList( long[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Long(array[i]));
    return result;
    public static List asList( float[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Float(array[i]));
    return result;
    public static List asList( double[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Double(array[i]));
    return result;
    // Now that we extend java.util.Arrays this method is not needed.
    // /**JCF already does this so just wrap their implementation
    // public static List asList(Object[] array) {
    // return java.util.Arrays.asList(array);
    public static List asList(Object object) {
    List result;
    Class type = object.getClass().getComponentType();
    if (type != null && type.isPrimitive()) {
    if (type == Boolean.TYPE)
    result = asList((boolean[])object);
    else if (type == Character.TYPE)
    result = asList(( char[])object);
    else if (type == Byte.TYPE)
    result = asList(( byte[])object);
    else if (type == Short.TYPE)
    result = asList(( short[])object);
    else if (type == Integer.TYPE)
    result = asList(( int[])object);
    else if (type == Long.TYPE)
    result = asList(( long[])object);
    else if (type == Float.TYPE)
    result = asList(( float[])object);
    else if (type == Double.TYPE)
    result = asList(( double[])object);
    } else {
    result = java.util.Arrays.asList((Object[])object);
    return result;
    I do not intend to instantiate com.tassajara.util.Arrays as all my methods are static just like java.util.Arrays. You can see where I started to wrap asList(Object[] o). I could continue and wrap all of java.util.Arrays methods, but thats annoying and much less elegant.

    Why can't classes with private constructors be
    subclassed?Because the subclass can't access the superclass constructor.
    I really, really want to be able to subclass
    java.util.Arrays, like so:Why? It only contains static methods, so why don't you just create a separate class?
    I do not intend to instantiate
    com.tassajara.util.Arrays as all my methods are static
    just like java.util.Arrays. You can see where I
    started to wrap asList(Object[] o). I could continue
    and wrap all of java.util.Arrays methods, but thats
    annoying and much less elegant.There's no need to duplicate all the methods - just call them when you want to use them.
    It really does sound like you're barking up the wrong tree here. I can see no good reason to want to subclass java.util.Arrays. Could you could explain why you want to do that? - perhaps you are misunderstanding static methods.
    Precisely as you said, if they didn't want me to
    subclass it they would have declared it final.Classes with no non-private constructors are implicitly final.
    But they didn't. There has to be a way for an API
    developer to indicate that a class is merely not to be
    instantiated, and not both uninstantiable and
    unextendable.There is - declare it abstract. Since that isn't what was done here, I would assume the writers don't want you to be able to subclass java.util.Arrays

  • How can a class be notified when an open file is modified externaly ?

    Hi!
    Can a class that open a File be notified when that file is modified by another program ? If yes how ?
    Thanks!

    I don't know that any operating system provides facilities to hook into the filestore this way (whatever language you're programming in). Probably the best you can do is to check the last modified time periodically.

  • Can a class implements more than one interface?

    Hello
    Can a class implements more than one interface?
    Thanks

    Of course, this doesn't mean that it won't be a problem though. If the two interfaces have methods with the same signature, but different return types, you won't be able to implement them together. I.E.
    interface InterfaceA {
      public int doSomething(String myString);
    interface InterfaceB {
      public String doSomething(String myString);
    // Now the classes
    // Gives error "Duplicate method doSomething(String) in type ClassA"
    public class ClassA implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    // Gives error "The return type is incompatible with InterfaceB.doSomething(String)"
    public class ClassB implements InterfaceA, InterfaceB {
      public int doSomething(String myString) {
        System.out.println("A");
        return 0;
    // Gives error "The return type is incompatible with InterfaceA.doSomething(String)"
    public class ClassC implements InterfaceA, InterfaceB {
      public String doSomething(String myString) {
        System.out.println("B");
        return 0;
    }

  • Why can't I interrupt the main thread from a child thread with this code?

    I am trying to find an elegant way for a child thread (spawned from a main thread) to stop what its doing and tell the main thread something went wrong. I thought that if I invoke mainThread.interrupt() from the child thread by giving the child thread a reference to the main thread, that would do the trick. But it doesn't work all the time. I want to know why. Here's my code below:
    The main class:
    * IF YOU RUN THIS OFTEN ENOUGH, YOU'LL NOTICE THE "Child Please!" MESSAGE NOT SHOW AT SOME POINT. WHY?
    public class InterruptingParentFromChildThread
         public static void main( String args[] )
              Thread child = new Thread( new ChildThread( Thread.currentThread() ) );
              child.start();
              try
                   child.join();
              catch( InterruptedException e )
    // THE LINE BELOW DOESN'T GET PRINTED EVERY SINGLE TIME ALTHOUGH IT WORKS MOST TIMES, WHY?
                   System.out.println( "Child please!" );
              System.out.println( "ALL DONE!" );
    The class for the child thread:
    public class ChildThread implements Runnable
         Thread mParent;
         public ChildThread( Thread inParent )
              mParent = inParent;
         public void run()
              System.out.println( "In child thread." );
              System.out.println( "Let's interrupt the parent thread now." );
              // THE COMMENTED OUT LINE BELOW, IF UNCOMMENTED, DOESN'T INVOKE InterruptedException THAT CAN BE CAUGHT IN THE MAIN CLASS' CATCH BLOCK, WHY?
              //Thread.currentThread().interrupt();
              // THIS LINE BELOW ONLY WORKS SOMETIMES, WHY?
              mParent.interrupt();
    }

    EJP wrote:
    I'm not convinced about that. The wording in join() suggests that, but the wording in interrupt() definitely does not.Thread.join() doesn't really provide much in the way of details, but Object.wait() does:
    "throws InterruptedException - if any thread interrupted the current thread +before+ or while the current thread was waiting for a notification. The interrupted status of the current thread is cleared when this exception is thrown."
    every jdk method i've used which throws InterruptedException will always throw if entered while a thread is currently interrupted. admitted, i rarely use Thread.join(), so it's possible that method could be different. however, that makes the thread interruption far less useful if it's required to hit the thread while it's already paused.
    a simple test with Thread.sleep() confirms my expected behavior (sleep will throw):
    Thread.currentThread().interrupt();
    Thread.sleep(1000L);

  • Can you only run one main() in a jar?

    Hi,
    I was just wondering if you can only ever run one main() method from a .jar file? I have a project being developed in Eclipse, consisting of several packages and then several classes with main()s in each of the packages. When the whole project is packaged into one big jar then I can run one of the main() methods by specifying it in the manifest, but as far as I'm aware I can't access the others.
    Is there some cunning way to call the main() method of a different class to that specified in the jar manifest, or do I have to compile every class as a separate jar? And if that's the case, is there really any advantage to putting the classes into a jar as opposed to just running from the .class files?
    Any help much appreciated. :)
    h

    Wow, thanks for the quick responses guys!
    You can execute the other main methods byexecuting:
    java -cp the-class-path TheMainClassIsn't that just what I'd use from the compiled .class
    files though?Correct, but you specify the jar on your classpath. e.g.
    java -cp myjar.jar TheMainClasss1 or
    java -cp myjar.jar TheMainClasss2
    For example:
    java -cp the-class-path my.class1
    java -cp the-class-path my.class2
    How does this relate to a single .jar file containing
    both of those classes? See above
    If I try those commands in the
    directory containing the .jar file, I just get a
    NoClassDefFoundError (they work fine in the directory
    with the .class files though).That's because you didn't specify the classpath in the correct way.
    Kaj

  • How do I set up an administrator account so my daughter who is under 13 , so she can access itunes herself. Main access will be via itunes vouchers . I don't want to create credit card access.

    how do I set up an administrator account so my daughter who is under 13 ,
    can access itunes herself. Main access will be via itunes vouchers . I don't want to create credit card access.

    There is no such account. The iPod is really a one-user device
    Create a NEW account/ID for her using these instructions. Make sure you follow the instructions. Many do not and if you do not you will not get the None option. You must use an email address that you have not used with Apple before.
      Creating an iTunes Store, App Store, iBookstore, and Mac App Store account without a credit card
    You can then redeem a gift card(s) into the account

  • Satellite L600: How can I turn off the main Wireless Communication Switch?

    Hello! Would be very grateful for any help....after struggling for 3 months I finally signed up here hoping to get some help.
    I have a new Satellite L600/ Win7 Home Premium.
    My questions is that I can not find where the MAIN wireless switch is in order to turn wireless off COMPLETELY.
    Everytime I start up, the wireless (orange) light switches on automatically.
    I have to wait till start up finish and manually turn it off by Fn-F8.
    When I open ConfigFree, (or Connectivity doctor), the diagnosis on the bottom left says [STATUS" Wireless Communication Switch: ON]
    This tells me the main switch is somehow still ON.
    I called Toshiba twice and they couldn't find it either.
    They said the new versions of BIOS doesn't allow it...? And for this model there is no physical switch built on the PC itself.
    I have looked everywhere and did the following:
    (1) Disable the adapter from Device manager.
    (2) In HWSetup, where there used to be an option to click the wireless switch off, it is not there anymore.
    (3) I went into BIOS setup and could find nothing remotely related to wireless/bluetooth to switch.
    I'm just wondering why there is a laptop with wireless switch ON permanently? But if it's ON, there must be a way to switch it off. Press Fn-F8 every time on start-up is not a long term solution as risk is I'll forget one day).
    As my last laptop was hacked before it is top priority that I know how to turn off ALL wireless function. So even if I have to do it via Commands, I will try it. Also, I'm not sure if anyone else experience the same with this model, or is this a defect in my particular PC?
    Any help or same experience will be much appreciated, thank you.
    I disabled the adapter in the device manager.
    When I open ConfigFree, the Connectivity doctor tells me the Wireless Communication Switch: ON

    Hi thanks for your replies! Sorry if I'm slow on the forum, at first I couldn't find where my thread went! Apparently it's moved to under Wireless. Is there alert message to let us know when my question is being moved?
    Thanks Paolo30, I am glad to know that Fn-F8 is enough. when I check Network Connections, the Atheros adapter is 'disabled'. Sorry may I ask if WLan card you are talking about in device manager = Atheros adapter? (Despite reading furiously on books to patch up my ignorance on the wireless last few weeks, still not sure the difference between 'adapter' and 'card'... :) Are they the same thing?
    Thanks Xardas. I checked the status in device manager and Atheros adapter is 'disabled'. I'm glad to know everything is ok if I see that! :) As my laptop was tampered wirelessly (and I don't know how they did it), I bought a new one and it's important for me to know it's 100% safe. Still, I want to tell Toshiba engineers it would be great to find out where this mysterious Switch is. It's not good to feel there is some sort of wireless capacity always ON and my PC may be emitting some wireless signals for serious baddies?

  • The main part of the safari page is grey and won't respond/can't type in any commands.  I can move back through the previous pages, and even open new ones via the URL, but can't get onto the main part of the page and I can't get onto the 9 page option. !?

    The main part of the safari page is grey and won't respond/can't type in any commands.  I can move back through the previous pages, and even open new ones via the URL, but can't get onto the main part of the page and I can't get onto the 9 page option. !?
    Help, please.

    Try clearing Safari's cache : Settings > Safari > Clear Cache (and Clear History)
    If that doesn't work then try closing Safari completely and then re-open it : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    A third option is a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

  • When I try to access the store I can't get to the main screen. It freezes up. I have the latest version.  An

    I can do everything in iTunes but get to the store.  When I try to access the store I can't get to the main screen. It freezes up. I have the latest version.  Can anyone provide any suggestions or help?

    Also try to reinstall itunes do no t worry no media will be erased.
    http://youtu.be/3c90vXO8K5w
    Look into what security software you are running and disable it and also go to apple.com/support and search for
    itunes store connection issues by actually typing that into the bar next to support then scroll down to one of the TS articles and begin a jounrey of internet explorer configuration.
    I have done the looking for you all:
    http://support.apple.com/kb/TS1379
    http://support.apple.com/kb/HT1527
    http://support.apple.com/kb/TS1368

  • I Just had my i phone replaced today, can I get extended applecare to cover it?

    My rear camera stopped working, so I booked a Genius Bar appointment to get it fixed for 10.1.14. Today, Apple very kindly replaced my i phone for a new one, I was extremely pleased with the fast and efficient service by Apple at Buchanan Street in Glasgow. I am just wondering, if I can get an extended Applecare for my new product in case the same happens again ? or how long it is guaranteed from when I have received it ?

    Hi
    You can purchase additional applecare warranty (from the store that did the warranty repair if you wish) that will extend the 1 year warranty you got when you purchased the iphone in the first place. You need to do this anytime up to and including day 364 of that first year.
    When you have have a warranty repair/replacement the warranty is only valid for that first year of if you've purchased additional appleware warranty, to the end of that additional warranty period.
    For example: In the 4th month of the first year's warranty - you still have 8 months left - your iPhone needs repairing/replacing because of a problem that's covered by the warranty. You'd still only have 8 months left. In other words you don't get another 12 months on the 8 months you have left.
    I think I've explained this correctly and HTH?
    Tony

  • Can applecare be extended with new logic board

    My Imac is with apple having a new logic board fitted for the second time and before that they replaced the computer. Since my cover runs out in August 09 has apple been known to extend the cover when replacing the logic boards, if so how do you go about it.

    If your iMac is still less than a year old, you can purchase the extended AppleCare out-of-pocket. If you already have an extended warranty, then you can no longer extend it any further.
    Technically, replacement parts (such as a logic board) can have longer warranties than the rest of the computer. This is because replacement parts are covered by either a 90-day warranty, or the remainder of the limited/extended warranty, whichever is longer. This means that if you had a logic board installed on the last day of your warranty, the logic board would still be under warranty for another three months even after the computer's warranty had expired.

  • If you buy an IPad online would it have an Apple warranty and can you get extended warranty from Apple

    If you buy an iPad online would it have an Apple warranty. Can you get extended warranty?

    If you buy it from the Apple Online store yes it will have full 1 year warranty, and the possibility to directly buy Apple Care +.
    If you buy it from somewhere else, it may not. If the online seller is not an Apple authorized reseller then you may need to take to to an Apple Store for physical inspection before purchasing the Apple Care Plus extension.
    If its not sealed and new, the warranty timer may have started to elapse, and it may not be eligible for Apple Care +.
    But without knowing where you plan to buy it its hard to say for sure.

  • Can you transfer extended warranty when you sell an ipad?

    Does anyone know if you can transfer an extended warranty to the new owner when you sell an ipad?

    Is the AppleCare Protection Plan transferable?
    Yes. If you choose to sell or give away your Apple product, you can also transfer the ownership of the AppleCare Protection Plan. Please see the AppleCare Protection Plan Terms and Conditions for complete details.
     Cheers, Tom

Maybe you are looking for

  • How do I get my contacts back on iPhone4?

    Lost all my contacts on my iPhone 4 and ipad.  How do I get them back without having to re-enter them?

  • Modifying a 6i form in 9i and running in 6i

    Hello all forum members, I have a fmb created in forms 6i. I am modifying the visual aspects of the form in forms 9i. After saving the file in forms 9i, can I open it in forms 6i and compile & run in forms 6i? I would be grateful if someone replies t

  • Autocommit feature in Oracle

    If I set the autocommit on and execute a transaction as follows: DELETE FROM TASK_LOG WHERE ROWNUM <= 100; is it that Oracle commits after deletion of each record or it that the commit occurs automatically after the 100 records have been deleted?

  • 'turning off' all filters from multiple clips at once???

    FCP 5.1.4 Is there a way to collectively disactivate or turn off the filters on a group of clips all at once? I'm making a spot using the material from the film. The master film sequences have a lot of filters assigned ... but the sequences are no lo

  • Imaqdx: (Hex 0xBFF69026) License not activated

    Hi All, I am trying run my vi, but every time I try to run the program I get error saying " NI-IMAQdx : Licensed not activated". When i go to License manager labview and vision acquisition software is green and activated. I have labview 2012 and VAS