Why abstract method Graphics.drawString() can work without implementation?

Hi All,
Can anybody gives me a clear answer and a code example for this ???
J.Kathir

it won't work,
java.awt.Graphics is abstract class,
also overloaded drawString() methods are abstract.
You can expect the above code work in two scenarios.
Either Graphics should be a concrete class or
drawString() should be a static method.
Or....
You forgot an important one. That was mentioned before. So thanks for the completely valueless contribution.

Similar Messages

  • Why am i able to use abstract methods id they aren't yet implemented?

    For example, why i can use this [http://docs.oracle.com/javase/7/docs/api/java/nio/CharBuffer.html#slice] if this is abstract?
    Edited by: 947971 on 13-set-2012 10.38

    947971 wrote:
    Yes, but if CharBuffer has a method declared:
    public abstract CharBuffer slice()So i can't use the method slice() because it's not implemented.
    And why , indeed, i'm able to use it?Because it is implemented by the actual class being used. You can't instantiate abstract classes, so there is a subclass of CharBuffer which does implement the method.
    If you take the interface Comparable, you see that it has an (implicitly)abstract method compareTo. A class that implements Comparable is Integer, so you can easily write:
    Comparable<Integer> i = new Integer(100);
    i.compareTo(new Integer(55));

  • [Solved] Browser that can work without mouse :)

    Hallo.
    I search for browser that i can work without mouse (only keyboard).
    Browser can be text browser or can be in GTK.
    Browser don't have to have Flash player.
    I need she to post posts on forums and see pictures on internet.
    I know Elinks,links,lynx there a any difrences between them.
    There are one?
    Thanks for anserws
    Last edited by SpeedVin (2009-06-16 20:03:31)

    uzbl is great, you should try it out (yaourt -S uzbl-git).  Lightweight, renders flawlessly, and keyboard controlled (although you can use the mouse too if you want).  No flash player required, and I imagine if a text browser is an option (it isn't for me) then you must be willing to put up with broken support for opening new windows via Javascript.

  • Why does this abstract class and method work without implement it?

    hi,
    I have seen many times that in some examples that there are objects made from abstract classes directly. However, in all books, manual and tutorials that I've read explain that we MUST implement those methods in a subclass.
    An example of what I'm saying is the example code here . In a few words that example makes Channels (java.nio.channel) and does operations with them. My problem is in the class to make this channels, because they used the ServerSockeChannel class and socket() method directly despite they are abstracts.
       // Create a new channel: if port == 0, FileChannel on /dev/tty, else
       // a SocketChannel from the first accept on the given port number
    private static ByteChannel newChannel (int netPort)
          throws Exception
          if (netPort == 0) {
             FileInputStream fis = new FileInputStream ("/dev/tty");
             return (fis.getChannel());
          } else {
    //CONFLICT LINES
             ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
             ssc.socket().bind (new InetSocketAddress (netPort)); //<--but here, this method (socket) is abstract. WHY RETURN A SOCKET????????  this mehod should be empty by default.
             System.out.print ("Waiting for connection on port "
                + netPort + "...");
             System.out.flush();
             ByteChannel channel = ssc.accept();
             ssc.close();
             System.out.println ("Got it");
             return (channel);
       } I test this code and works fine. So why can it be??
    Also, I read that the abstract classes can't have static methods. Is it true???
    Please Help!!
    PS: i have seen this kind of code many times. So i feel that I don't understand how its really the abstract methods are made.
    PS2: I understand that obviously you don't do something like this: *"obj = new AbstractClass(); "*. I dont understand how it could be: ServerSocketChannel ssc = ServerSocketChannel.open(); and the compiler didn't warn.

    molavec wrote:
    ServerSocketChannel ssc = ServerSocketChannel.open(); //<--I have never thought do that!! Anyway, how it is static method may work.
    The static method creates an instance of a class which extends ServerSocketChannel, but is actually another non-abstract class.I thought that, but reading the documentation I saw that about open() method:
    Opens a server-socket channel.
    The new channel is created by invoking the openServerSocketChannel method of the system-wide default SelectorProvider object.
    The new channel's socket is initially unbound; it must be bound to a specific address via one of its socket's bind methods before connections can be accepted.
    ...and the problem is the same openServerSocketChannel is abstract, so i don't understand how it could return a ServerSocketChannel.There is a concrete implementation class that has implemented that method.
    I guess that really the open() method use a SelectorProvider's subclase but it doesn't appear in the doc.It doesn't need to. First, you don't care about those implementation details, and second, you know that if the class is abstract, it must use some concrete subclass.
    Ok, I speak Spanish by default (<-- this sounds like "I am a machine", ^_^' ). So, I didn't know how to say that the method would be {}. Is there a way to say that?? I recommendable for me to know, for the future questions o answers.Not sure what you're saying here. But the other respondent was trying to explain to you the difference between an abstract method and an empty method.
    // abstract method
    public abstract void foo();
    // empty method
    public void bar() {
    Which class does extend ServerSocketChannel? I can not see it.It may be a package-private class or a private nested class. There's no need to document that specific implementation, since you never need to use it directly.

  • Anyone know of a Voice Translator that can work without WIFI?  for travel

    would like to find a Voice Translator APP  (don't care about cost) that works without WIFI  - for Travel use in some areas with little or no wifi service.

    Hey Calchick, I didn't read much of the details, only looked for key words, like offline, translation, etc. Illaass is correct, voice recognition and translation programs tend to be very large. If you have web access, you can talk in your native language and be heard in the foreign language. With out the web, your a text and read operation.
    Personal experience, may help you, take of it what you will-- in BC time, (Before Computers) and traveling around, I found if you learn a few basic phrases in the language of the people you are visiting, i.e., things like, "Can you help me?", "Where am I" (have a map in hand when you ask this), "Where is the bathroom", "How much?", "Where do you go eat", "Where's the market?", "Take me to the pharmacy / hospital", and the most important phrase: "Thank You" I know, dumb examples but you get the point, about 20 phrases that cover the basics, who, what, where, when, and how, (think about the questions or things you would ask if you were in a city, in the country you now live, that you have never been in) and a working knowledge of some basic answers, (also, learn a few cruse words, that way you will know if your getting help or the butt of a joke), along with a translation guide book, you can get through almost any situation. Being able to speak even just a little of the other persons language, without using a device, will make most people want to help you, (unless you get a real A-hole), most people will help you if you make an attempt to learn and speak there language, even if it's just a little, (shows you cared enough to try). The translator app just replaces the book, and it will make it easier to learn the phrases. Remember; The app is just a tool, not your mouth. It can get a little rough at times, but generally works, got me through a few countries and made a few friends along the way. Having a soccer ball helps too! Hope this helps, have good travels. Cheers.

  • Sony smartwatch can work without the phone?

    hey guys!i dont know if i can post its here idk where but i have to know!
    i bougt smratwatch today everythngs worked great(with galaxy S3)
    now i dont have the phone near me just the watch
    and its not working he show to me that he need the phone!
    pls someone help me!i want use it without the phone to!
    idk what to do!

    As I understand the SmartWatch needs to be connected to the phone to be able to show date/time etc.
     - Community Manager Sony Xperia Support Forum
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • Why setValueExpression method for inputText not working properly

    Hi,
    JDev Ver : 11g 11.1.1.2.0
    I have set value property of input text using setValueExpression method.
    First time its working fine and setting value properly but when I set blank value using same setValueExpression method then input text automatically become read only.
    I have not explicitly set read only true anywhere in my code.
    For settting value I am using #{bindings.iProductName.inputValue} expression while resetting I am using #{''} value expression.
    Is there any bug with this method or the I have done is wrong ?
    Pls give your comment on this.
    Thanks
    regards,
    devang

    Hi,
    You're doing something very wrong. If you want to reset the value, you reset the value, not modify the expression. So you need to call .setInputValue(null) on the ValueBinding. #{''} is a r-value, thus read-only.
    Regards,
    ~ Simon

  • Why wont my iphone's internet work without wifi?

    two days ago I restored my phone with itunes backup and now I can't use my internet without wifi. my cellular data is on, i have unlimited data,and i took it to the store and they didn't give me any help. any advice on what i can do to fix this?

    i first took it to the cricket store (my cell phone carrier) and they said they only cover talk and text since my phone is flashed over. so i took it to the store i flashed it at and they said the ios7 update prevents them from fixing any problems (which made no sense to me) i have full bars in some places usually 3g next to it but some times i have low bars with 1x next to it

  • Method Graphics not entered, why?

    Why the method Graphics(Graphics g) is not beeing entered?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SwingApplication extends JFrame
         public SwingApplication()
              super("SwingApplication");
              Component contents = this.createComponents();
              getContentPane().add(contents, BorderLayout.CENTER);
              pack();
              setVisible(true);
         public Component createComponents()
              JPanel pane = new JPanel();
              pane.setBorder(BorderFactory.createEmptyBorder(400, 600, 0,0));
              pane.setBackground(Color.YELLOW);
              pane.setLayout(new GridLayout(0, 1));
              return pane;
         public void Graphics(Graphics g)
              System.exit(0);
         public static void main(String[] args)
              new SwingApplication();
    }

    Why would it be? You never call the method, I think you mean to override paint. Change:
    public void Graphics(Graphics g)to:
    public void paint(Graphics g)That should be what you meant. Also, you shouldn't name your method Graphics, it's a class in the java.awt.

  • SAP Notes status can't be implemented?

    Hi All
    I would like to know, why few SAP notes status can't be implemented.
    your view will be appreciated and will rewarded with <<removed by moderator>>.
    Regards
    Madhavi
    Edited by: kishan P on Sep 1, 2010 1:03 PM

    HI
    Some SAP note can be implement manually and some are can be implement through the T-Code SNOTE
    once you go to the look at the sap note it provide the instruct how to implement ,
    when you go to SNOTE T-code in the GOTO> DOWNLOAD SAP NOTE once u click it you have to download SAP note direcly in to SNOTE and you can directly implement .
    if its not downloading to this place you have to do it manually from taking the access key from SAP .
    Regard
    nawa

  • Why can't there be a simple utility that shows me which device connected to my Airport is using how much of the bandwidth in a simple graphical or stats format without requiring me to be a level 10 Black Belt or Chuck Norris' paternal tooth fairy?

    Why can't there be a simple utility that shows me which device connected to my Airport is using how much of the bandwidth in a simple graphical or stats format without requiring me to be a level 10 Black Belt or Chuck Norris' paternal tooth fairy?
    I need to see who is consuming the most bandwidth and limit that user/device. A very simple and dare I say it, legal, moral, and normal wish.

    They are not overloading the Airport. They are overwhelming the capacity of your Internet connection.
    No. It's not "shared equally". That's not how packet switched networks function.
    Most consumer grade routers do not have the ability to restrict bandwidth use on a per machine basis. You need relatively expensive (but readily available) equipment to do that.
    How many people are on the network? It can't be that hard to hunt them down.

  • Mozilla can't find a valid PDF file to open in a browser, but Chrome or IE work without problem. Why?

    The system I'm running is Scientific Linux.
    PDF files, I need to open in a browser, are on the file server, but in the same folder as my html files, etc.
    So, in HTML I gave the link to some PDF to open it in the browser, however, Mozilla says it can't find the file by the given URL.
    Proper permissions to access the files are given.
    All is lowercase, no spelling error.
    On Chrome, on the same computer, everything works fine.
    I've also tested on Windows, still Chrome or IE work without problem.
    Any ideas?

    Thanks for your reply!
    I've checked the link, and everything is set to its normal form in my browser.
    Otherwise this particular case, the browser has no problems viewing PDF files,
    but here, when I try to open the PDF (using HTML code, say,
    href="downloads\file1.pdf" where "downloads" is a folder on the same level as the html file) then the error I am getting is this
    Not Found
    The requested URL (the name) was not found on this server.

  • Static abstract methods - how can I avoid them?

    Hi everybody,
    just found out that java doesn't allow static abstract methods nor static methods in interfaces. Although I understand the reasons, I can't think of how to change my design to gain the required behavior without the need of static abstract methods.
    Here's what I want to do and how my thoughts lead to static abstract methods:
    ClassA provides access to native code (c-dll, using jna). The path to the dll can be set programmatically. Here's a draft of the class:
    public ClassA {
       private static String path;
       public static void setRealtivePath(String path) {
          //check if path exists and is not null -> get absolute path
          setPath(path);
       public static void setPath(String absolutePath) {
          this.path = path;
      //code to provide access to native lib
    }There is some more classes which provide access to different dlls (therefore the code for accessing the dlls differs from ClassA). Although this works, the setRelativePath method has to be implemented in each class. I thought it would be nice to put this method into a abstract super class that looks like this:
    public abstract class superClass {
       public static void setRelativePath(String path) {
          //check if path exists and is not null -> get absolute path
          setPath(path);
       //force inherting class to implement a static method
       public static abstract void setPath(String absolutePath);
    }thus simplifying ClassA and it's look-a-likes:
    public ClassA {
       private static String path;
       @Override
       public static void setPath(String absolutePath) {
          this.path = path;
      //code to provide access to native lib
    }Since static abstract methods (and overriding static methods) is not allowed, this doesn't work.
    I hope someone can catch my idea ;). Any suggestions how to do this in a nice clean way?
    Thanks in advance,
    Martin
    Edited by: morty2 on Jul 22, 2009 2:57 AM

    First of all, thanks a lot for your answer.
    YoungWinston wrote:
    Actually, you can "override" static methods (in that you can write the same method for both a subclass and a superclass, providing the superclass method isn't final); it's just that it doesn't work polymorphically. The "overriding" method masks the overridden one and the determination of what gets called is entirely down to the declared type.Yes, I know that. There's one problem: Your suggestion means that I simply have to drop the abstract modifier in the super classes setPath method. However, since the super class calls the setPath method (and not the inherting classes!) it will always be the super classes' method being called.
    YoungWinston wrote:
    Why are you so concerned with making everything static? Seems to me that the simplest solution would be to make all the contents instance-based.I want ClassA and it's look-a-likes to be set up properly at application start up, be accessible quite anytime and easily, they don't do anything themselves except for setting the path and calling into the native library which does the math. (Compareable to how you call e.g. Math.cos()). Therefore I don't think that an instance-based solution would be a better approach.
    YoungWinston wrote:
    Furthermore, you could make the class immutable; which might be a good thing - I'm not sure I'd want someone being able to change the pathname after I've >set up a class like this.Thanks for that!
    PS: As mentioned in my first post, I do have a working solution. However, I'm really corious about finding a nicer and cleaner way to do it!
    Martin

  • Why java does not force to declare atleast one abstract method

    hi,
    i can define an abstract class without declaring any abstract method in that class. But why wud i do this ? i mean when i have decided that a particular class should be inherited by other subclass and subclass should porvide implementation then there should be atleast one method in the abstract super class which requires implementation.
    All i want to know is why java does not force to declare atleast one abstract method in abstract class.
    there may be some situations where this restriction can create problem if it is like that then can anybody give some example.
    manish

    hi,
    i didn't get u.
    u r trying to say that i have an abstract class with
    only static methods then my questions is why wud
    declare such a class as 'abstract' class? because a
    static method can't be abstract also. Even then if
    somebody want to define such a class with only static
    methods then compiler should force him to declare
    atleast one abstract method which can be implemented
    by subclass, because as i said before if sumbody
    decide to define a class abstract then he wants that
    it should be inhereted but as u r saying a class with
    only static methods then it should not be an abstract
    class it can be a simple class.there's no functional reason, really... actually, factory-like classes are often defined the way Ceci described
    "abstract" only ensures that nobody can ever get an instance of that class (as a matter of fact, what would be the point of getting an instance, if no instance method exists ?)

  • Can i call non -abstract method in abstract class into a derived class?

    Hi all,
    Is it possible in java to call a non-abstract method in a abstact class from a class derived from it or this is not possible in java.
    The following example will explain this Ques. in detail.
    abstract class A
    void amethod()
    System.out.println(" I am in Base Class");
    public class B extends A
    void amethod()
    System.out.println(" I am in Derived Class");
    public static void main (String args[])
    // How i code this part to call a method amathod() which will print "I am in Base Class
    }

    Ok, if you want to call a non-static method from a
    static method, then you have to provide an object. In
    this case it does not matter whether the method is in
    an abstract base class or whatever. You simply cannot
    (in any object oriented language, including C++ and
    JAVA) call a nonstatic method without providing an
    object, on which you will call the method.
    To my solution with reflection: It also only works,
    if you have an object. And: if you use
    getDeclaredMethod, then invoke should not call B's
    method, but A's. if you would use getMethod, then the
    Method object returned would reflect to B's method.
    The process of resolving overloaded methods is
    performed during the getMethod call, not during the
    invoke (at least AFAIK, please tell me, if I'm wrong).You are wrong....
    class A {
        public void dummy() {
             System.out.println("Dymmy in A");
    class B extends A {
         public void dummy() {
              System.out.println("Dymmy in B");
         public static void main(String[] args) throws Exception {
              A tmp = new B();
              Class clazz = A.class;
              Method method = clazz.getDeclaredMethod("dummy", null);
              method.invoke(tmp, null);
    }Prints:
    Dymmy in B
    /Kaj

Maybe you are looking for

  • Rollback AI 17.1 update and go back to AI 17.0.0

    How can I rollback AI 17.1 update to go back to 17.0.0.  I have issues with SVG 1.1 Tiny header in the new version.

  • My Rotated Images Do Not Save.

    I just processed my entire photography collection with Bridge. I rotated many of the photos. But now, as I'm looking at the folders in Windows Explorer, I notice that none of the images appear as being rotated. After reading the product support for r

  • How does time machine use the external disk space??

    does time machine back up only the changed or new stuff or does it back up everything?  does this mean that if on "day one" it backed up 600 gb worth of data, the next back up on "day 2" would be 600gb+a few more things, or would it be 600gb+600gb+th

  • MIGO GR Price Diff Accounts

    Dear Gurus, Please help me that system create GR Price Diff. Po Order  : Po Curr is INR qty 16000 PC Rate Rs. 47.00 Per PC Value 752,000.00 INR Material : M.CD : 201305   Price Control : S  Moving Price :  35.90   STD Price : 45.80    Previous Price

  • Integrated Excel view in SAP

    Hi, our consultant need the FICO report in EXcel view in SAP inself. ( not save as local file in desktop ) it say as the view is not switched due to the procuct is not available. the message no : OK000.    HOW TO SEE THE MESSAGE IN  service.sap.com ?