Results 1 to 3 of 3
  1. #1
    haoberoi is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Question why we cann't override static methods

    1 class A{
    2 static void go() {
    3 System.out.println("red");
    4 }
    5 }
    6 class B extends A {
    7 static void go () {
    8 System.out.println("green");
    9 }
    10 public static void main(String args[]) {
    11 go(); //outputs green
    12
    13 A a=new B();
    14 a.go();//outputs red
    15 }

    from line 11 it seems method is overridden
    but from 14 , we get to know its not overridden

    why is the difference? why cann't we override the static methods? Is there any use of static method? Is there any advantage of static method over instance method

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. How To Override Methods, NetBeans 6.1
    By markw8500 in forum NetBeans
    Replies: 1
    Last Post: 08-16-2008, 11:58 PM
  3. Override Methods In NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-30-2007, 11:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •