- 3
Why my code does not work? [solved]
Here is my code: Can anyone help me? https://code.sololearn.com/cywV8UQN3IGT/?ref=app
17 Réponses
+ 3
Overiding a method should have same return type
In the code you changed the return type so it's throwing u the error
Change the return type to same in overriding method to same as overridden method or vice versa and 1 more thing for abstract class(" Circle b = new Circle(y)" ) u can't create object
+ 2
your mistake : while overriding abstract class , the signature of methods should be same. and also Circle class wasn't supposed to be abstract.
here is a working example :
https://code.sololearn.com/ckfESWf1TdBL/?ref=app
hope that helps.
+ 2
KindCat
I have updated the code.
now try and say .
My mistake : The sololearn judge was expecting a double. So casting the value to double should work.
+ 2
KindCat
No.
In the return type of area() of Circle type.
sololearn provides (for this question) int as input.
See my code i have updated and tested it :
https://code.sololearn.com/ckfESWf1TdBL/?ref=app
+ 1
Prashanth Kumar, in the main, I should read double type?
+ 1
Prashanth Kumar
No need to cast (Math.PI * width * width) with double because Math.PI is already a double value.
+ 1
https://code.sololearn.com/cu89ghPUQgCS/?ref=app
Here I have solved the problem and explained everything in the comment
0
Help you, Prashanth Kumar and Nivya. But my code still doesn't pass all tests.
My code passes 1st, 2nd, 4th and 5th tests.
0
I'm sorry ,where is the problem statement by the way?
0
Here is my final code. But there is some error with brackets. I don't understand where is an error.
https://code.sololearn.com/cFt4CkuSrF7Y/?ref=app
0
Prashanth Kumar , thank you very much!
0
What does it mean:
import java.lang.*
?
Prashanth Kumar
0
KindCat
java.lang is a package and .* means all classes in that package.
So if you write import java.lang.*; then all classes will be import
0
Prashanth Kumar
KindCat
No need to import java.lang.*; package because it is bydefault imported by JVM.
0
What does it do? I understand that * is "all"
0
In the code u have mentioned abstract class void area that and in overriding u gave mentioned it as int area() and u have mentioned circle class as a abstract
0
Thanks for everyone