- 2

inheritance

I am a basic learner, look my question as I mentioned basic, now, when I am trying to use inheritance it is giving compile time error in my intellij please help me with this

18th Apr 2022, 1:54 AM
Luk Armaan
5 Answers
+ 4
Save a copy of your code as new code bit in SoloLearn, then share link to the saved code, in your post's Description. https://www.sololearn.com/post/75089/?ref=app Asking code related question without the presence of the code was like asking a stranger to tell your fortune. None of us here knows what you're doing with the code, you can't simply ask why ... (Edited)
18th Apr 2022, 2:47 AM
Ipang
0
public class Program { public static void main(String[] args) { Shape s=new Shape(); Circle c=new Circle(); s.color="select color"; c.color1="white"; s.display(); c.display1(); } class Shape{ String color; void display(){ System.out.println(color); } class Circle extends Shape{ String color1; void display1(){ System.out.println(color1); } } } }
18th Apr 2022, 3:54 AM
Luk Armaan
0
This is i have written the code in my intellij. But its asking me to make class as static
18th Apr 2022, 3:55 AM
Luk Armaan
0
But when i was looking at others code they were not creating static class
18th Apr 2022, 3:55 AM
Luk Armaan
0
An object of `Shape` class is instantiated inside Program.main(), which is a static method. Shape s = new Shape(); Always remember, anything used inside static methods will also need to be defined as static (including that `Shape` class), to match the scope (class wise scope opposed to instance wise scope). Your snippet was missing the definition of `Circle` class.
18th Apr 2022, 4:17 AM
Ipang