Eleven Years of Service
Posts: 65
Threads: 5
Points: 0€
RE: interfaces help 11-27-2013, 03:08 AM
#21
Okay. The @override is how you override a method in Netbeans. Override simply means that the method is inherited but you don't want to use the inherited code, you want to use your own code which you provide.
Next, what is the scope of the name variable? is it local or an instance variable? If its local in another method you can't use it in a different method.
Lastly, since you did an override on toString() I'm not sure if you can use it in the same manner. You may have to use it as a regular method (i.e. toString(purchasePrice);
This seems weird because from what you are saying you need to create a toString() when one already exists.
Maybe you can choose a different method name other than toString but use toString() in that method. You will get the result you need without the headache and without overriding toString().
•
Eleven Years of Service
Posts: 65
Threads: 5
Points: 0€
RE: interfaces help 11-27-2013, 03:08 AM
#22
Okay. The @override is how you override a method in Netbeans. Override simply means that the method is inherited but you don't want to use the inherited code, you want to use your own code which you provide.
Next, what is the scope of the name variable? is it local or an instance variable? If its local in another method you can't use it in a different method.
Lastly, since you did an override on toString() I'm not sure if you can use it in the same manner. You may have to use it as a regular method (i.e. toString(purchasePrice);
This seems weird because from what you are saying you need to create a toString() when one already exists.
Maybe you can choose a different method name other than toString but use toString() in that method. You will get the result you need without the headache and without overriding toString().
•
Eleven Years of Service
Posts: 65
Threads: 5
Points: 0€
RE: interfaces help 11-27-2013, 03:36 AM
#25
Only thing I can see that could be wrong is this:
@Override
public String toString(){
return name;
return purchasePrice.toString(); //calls your override method
return salePrice.toString(): //uses colon instead of semicolon
//calls your override method
}
You used a colon instead of a semicolon on your last statement. Since you did a override on toString(), you are calling your method on the statements inside of your method.
Don't override toString(). Change its name to something else and try to compile. That will let you know if that's the problem.
•
Eleven Years of Service
Posts: 65
Threads: 5
Points: 0€
RE: interfaces help 11-27-2013, 03:36 AM
#26
Only thing I can see that could be wrong is this:
@Override
public String toString(){
return name;
return purchasePrice.toString(); //calls your override method
return salePrice.toString(): //uses colon instead of semicolon
//calls your override method
}
You used a colon instead of a semicolon on your last statement. Since you did a override on toString(), you are calling your method on the statements inside of your method.
Don't override toString(). Change its name to something else and try to compile. That will let you know if that's the problem.
•
Eleven Years of Service
Posts: 909
Threads: 43
Points: 0€
RE: interfaces help 11-27-2013, 01:29 PM
#27
well i changed the name the method name fixed the semicolon but still i get int cannot be dereferenced
anw i searched for the exercice on the net and found it he changed in the question it shouldnt b toString i'll work on the original 1 unless some1 tell me it is possible to do it for his wuestion
(This post was last modified: 11-27-2013, 01:40 PM by LordPankake.)
•
Eleven Years of Service
Posts: 909
Threads: 43
Points: 0€
RE: interfaces help 11-27-2013, 01:29 PM
#28
well i changed the name the method name fixed the semicolon but still i get int cannot be dereferenced
anw i searched for the exercice on the net and found it he changed in the question it shouldnt b toString i'll work on the original 1 unless some1 tell me it is possible to do it for his wuestion
(This post was last modified: 11-27-2013, 01:40 PM by LordPankake.)
•
Eleven Years of Service
Posts: 909
Threads: 43
Points: 0€
RE: interfaces help 11-27-2013, 02:18 PM
#29
i just have 1 question in my mind for now maybe @Deque could give me a good explanation to this !!
why do i need to make interfaces then inplement them couldnt i just make those methodes inside the class ?
•
Eleven Years of Service
Posts: 909
Threads: 43
Points: 0€
RE: interfaces help 11-27-2013, 02:18 PM
#30
i just have 1 question in my mind for now maybe @Deque could give me a good explanation to this !!
why do i need to make interfaces then inplement them couldnt i just make those methodes inside the class ?
•