Leon Peeters

Greenhorn
+ Follow
since Nov 22, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Leon Peeters

Hi, rvamsi
In the case of above code, we have two methods in Child class(Please correct me if I��m wrong):
Method 1: public void draw(float l) {/*��*/} (Inheriting from superclass work23)
Method 2: public void draw(double ll) {/*��*/} (overloading in Child class)
On the method call ch.draw(10.0F), compiler will decide which is the ��most specific�� method to invoke( That would be Method 1). Am I right?
So it won��t be ambiguous in fact. How the compiler complain about ambiguous method? I am confusing about this.
Question: The GenericFruit class declares the following method.
Public void setCalorieContent(float f)
You are writitng a class Apple to extend GenericFruit and wish to add methods which overload the method in GenericFruit.
Select all of the following which would constitute legal declarations of overloading methods.
a. protected float setCalorieContent(String s)
b. protected void setCalorieContent(float x)
c. public void setCalorieContent(double d)
d. public void setCalorieContent(String s) throws NumberFormatException
The key answer is a,c,d However , I am wondering about
answer c. Look at following code which comes from this forum:
public class work23 {
work23()
{
System.out.println("default");
}
work23(int i)
{
System.out.println("int");
}
work23(long l)
{
System.out.println("long");
}
public void draw(float l)
{
System.out.println("draw parent");
}
public static void main ( String a[])
{
work23 w = new work23(23);
child ch = new child(10);
ch.draw(10.0F);
}
}
class child extends work23 {
child(int k)
{
System.out.println("child int");
}
public void draw(double ll)
{
System.out.println("drawing long child");
}
}

Compile error! The line ��ch.draw(10.0F);�� is supposed to call the method inherited from superclass work23 because the compiler will look up the ��most specific�� method (which is the one inherited from superclass work23). But there is a compiler error?
Can you guys explain something on this? Thank you very much!
Which category does java.awt.Container belong to?
1.interface
2.abstract class
3.normal class
4.none of the above
Key answer is 3. But I think it is 2.
Can someone explain this? Thanks!
Appreciate for your comments, Kavitha and Ankur!
Can anyone tell me why the following code can not be
compiled?
public class Base {
System.out.println( "We hit infinity!");
}
Compile error:Type expected.
Would you explain this for me? Thanks in advance!