+ 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(); }
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();
}
}
+ 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.
+ 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
0
I still didn't get what's wrong?
0
Can u highlight my mistake