- 3

Why my code does not work? [solved]

Here is my code: Can anyone help me? https://code.sololearn.com/cywV8UQN3IGT/?ref=app

20th Jun 2021, 3:23 PM
Kind_Cat
Kind_Cat - avatar
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
20th Jun 2021, 4:18 PM
Nivya
Nivya - avatar
+ 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.
20th Jun 2021, 4:48 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 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.
20th Jun 2021, 4:58 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 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
20th Jun 2021, 5:28 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 1
Prashanth Kumar, in the main, I should read double type?
20th Jun 2021, 5:04 PM
Kind_Cat
Kind_Cat - avatar
+ 1
Prashanth Kumar No need to cast (Math.PI * width * width) with double because Math.PI is already a double value.
20th Jun 2021, 6:03 PM
A͢J
A͢J - avatar
+ 1
https://code.sololearn.com/cu89ghPUQgCS/?ref=app Here I have solved the problem and explained everything in the comment
21st Jun 2021, 11:19 AM
Hasib Arya
Hasib Arya - avatar
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.
20th Jun 2021, 4:54 PM
Kind_Cat
Kind_Cat - avatar
0
I'm sorry ,where is the problem statement by the way?
20th Jun 2021, 5:05 PM
Nivya
Nivya - avatar
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
20th Jun 2021, 5:20 PM
Kind_Cat
Kind_Cat - avatar
0
Prashanth Kumar , thank you very much!
20th Jun 2021, 5:36 PM
Kind_Cat
Kind_Cat - avatar
0
What does it mean: import java.lang.* ? Prashanth Kumar
20th Jun 2021, 5:36 PM
Kind_Cat
Kind_Cat - avatar
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
20th Jun 2021, 5:55 PM
A͢J
A͢J - avatar
0
Prashanth Kumar KindCat No need to import java.lang.*; package because it is bydefault imported by JVM.
20th Jun 2021, 6:07 PM
A͢J
A͢J - avatar
0
What does it do? I understand that * is "all"
20th Jun 2021, 7:12 PM
Kind_Cat
Kind_Cat - avatar
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
21st Jun 2021, 3:09 AM
Kolla Vinod
Kolla Vinod - avatar
0
Thanks for everyone
21st Jun 2021, 11:21 AM
Kind_Cat
Kind_Cat - avatar