+ 1

What is wrong in this code

class Program { public void start() { System.out.println("evil"); } } public static void main(String[] args) { Program m1= new Program() { @Override public void start() { System.out.println("hehe"); } }; Program m2 = new Program(); m2.start(); }

3rd Feb 2022, 3:47 PM
Shashi Singh
Shashi Singh - avatar
5 Answers
+ 2
// This is only the main needed change, but I donā€˜t know what you want class Program { public void start() { System.out.println("evil"); } public static void main(String[] args) { Program m1= new Program() { @Override public void start() { System.out.println("hehe"); } }; Program m2 = new Program(); m2.start(); } }
3rd Feb 2022, 3:52 PM
JaScript
JaScript - avatar
+ 2
shashisingh singh Much more beneficial to all of us who need help and those who support, if you save the code on SoloLearn Playground and provide a link here.
3rd Feb 2022, 4:17 PM
JaScript
JaScript - avatar
+ 1
You misplaced the } for end of class block (it's placed after void start definition). If you want to see "hehe" then call start() from <m1> where start() was overridden. class Program { public void start() { System.out.println("evil"); } // end start() public static void main(String[] args) { Program m1= new Program() { @Override public void start() { System.out.println("hehe"); } }; m1.start(); } // end main() } // end class
3rd Feb 2022, 4:10 PM
Ipang
0
I still didn't get what's wrong?
3rd Feb 2022, 4:04 PM
Shashi Singh
Shashi Singh - avatar
0
Can u highlight my mistake
3rd Feb 2022, 4:05 PM
Shashi Singh
Shashi Singh - avatar