mad dy

Greenhorn
+ Follow
since Jun 27, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by mad dy

hi

thnks for the solution
its working
Thanks All,

Now I got the clear Idea.

As the static method of Super class is hidden, so it is not inherited to the Sub Class.
So there is no issue of overridding the super class static method in Sub class,
and the sub class will treat its static method as it's own method...

Am I Right???
Hi,

when I compi led and run this program i got o/p "a a a"

wht my question exactly is by seeing the code it looks like overriding the method dostuff in subclass Dog...
but actually it is redefining it..
I'm not able to understand the difference b/w them
hi,

Static methods can't be overridden but they can be redefined (from K&B)
class Animal {
static void doStuff() {
System.out.print("a ");
}
}
class Dog extends Animal {
static void dostuff() { // it's a redefinition, not an override
System.out.print("d ");
}
public static void main(String [] args) {
Animal [] a = {new Animal(), new Dog(), new Animal()};
for(int x = 0; x < a.length; x++)
a[x].doStuff(); // invoke the static method
}
}

in this how to recognise tht dostuff() is redefined??
Hi,

I hope this is correct.

1)Class A is abstract class which contains one abstract instance method math().
2)in Class B,4 static objects of class A are instantiated.
3)and for each object the abstarct math method is overridden differently.
static A a1 = new A() {
public int math() {
return x()+y(); // will return 4 + 2 = 6
}
};
static A a2 = new A() {
public int math() {
return x()-y(); // will return 4 - 2 = 2
}
};
static A a3 = new A() {
public int math() {
return x()*y(); // will return 4 * 2 = 8
}
};
static A a4 = new A() {
public int math() {
return x()/y(); // will return 4 / 2 = 2
}
};
4)print statement will give the o/p 6282


Cheers
Maady
Hi,

congratulations

thanks for sharing useful info

cheers
maady
17 years ago
Hi,

For Upgrade 1.5 Exam (CX-310-056),Prerequisite is Successful completion of previous version of Sun Certified Programmer for Java 2 Platform exam.

I think you can go for this with 1.4

cheers,
maady