aspose file tools
The moose likes Beginning Java and the fly likes doubt in static methods.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "doubt in static methods.." Watch "doubt in static methods.." New topic
Author

doubt in static methods..

s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
Can we override static methods?



With Regards,
S.Palanivel Rajan B.E.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 268
Does it make sense? How do you access a static method? Have you tried?
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
actually we can access static methods by using the class name..i know that if we write the code as below what will happens..

class rajan
{
public static void sum()
{
System.out.println("i am base class");
}
}
class erode extends rajan
{
public static void sum()
{
System.out.println("i am derived class");
}
}
class rajanerode
{
public static void main(String args[])
{
erode e=new erode();
e.sum();
}
}
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 268
But have you tried?? What do you deduce from the result?

Otherwise take a look at this: http://faq.javaranch.com/view?OverridingVsHiding
s.palanivel rajan
Ranch Hand

Joined: Sep 22, 2009
Posts: 40
actually what will be the output for my code because i cant try here..sorry..please give me the output..
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 268
You have the answer in the link I posted before.
swapnl patil
Ranch Hand

Joined: Aug 13, 2007
Posts: 80
for this program

class rajan
{
public static void sum()
{
System.out.println("i am base class");
}
}
class erode extends rajan
{
public static void sum()
{
System.out.println("i am derived class");
}
}
class rajanerode
{
public static void main(String args[])
{
erode e=new erode();
e.sum();
}
}

method from class erode will get called .

A static method cannot override an inherited instance method, but it can hide a static method if the exact requirements for overriding
instance methods are fulfilled. A hidden superclass static method is not inherited. The compiler will flag an error if the signatures are the
same but the other requirements regarding return type, throws clause, and accessibility are not met. If the signatures are different, the
method name is overloaded, not hidden.

let me know if you have any quires.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Please note your code is much harder to read unless you use the CODE button.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: doubt in static methods..
 
Similar Threads
static and non-static synchronized methods
What is the logic behind calls like JOptionPane.method()
method overriding
Static methods can be overridden by static methods only?
Inheritance of all members