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
posted
0
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
posted
0
But have you tried?? What do you deduce from the result?
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
posted
0
You have the answer in the link I posted before.
swapnl patil
Ranch Hand
Joined: Aug 13, 2007
Posts: 80
posted
0
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
posted
0
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.