+ 3
What's an error??
11 Respostas
+ 7
You cannot make class inside class instead of static class.
make Animal class outside Program class
or make Animal class static
public class Program {
static class Animal {
public void makesound(){
System.out.println("AJ");
}
public void makesound(String dog) {
System.out.println (dog);
}
}
public static void main(String[] args) {
Animal abc = new Animal();
abc.makesound();
}
}
+ 3
Additionallly, I would recommend you to remove the blank spaces:
System.out.println(...)
Instead of
System. out .println (...)
+ 3
Its a special problem of an inner class.
Define class Animal out of class Program.
+ 2
subrat yadav
Please after writing code check again what you are doing?
You have many mistakes
1 - extends class Animal should be extends Animal
2 - public not publ8c
3 - void not voud
// Created by NonStop CODING
// why it has no output
// Created by subrat yadav
class Animal{
void makesound(){
System.out.println("space");
}
void makesound(String dog){
System.out.println(dog);
}
}
class Cat extends Animal {
public void makesound(){
System.out.println("meau meau");
}
}
public class Program
{
public static void main(String[] args) {
Animal abc= new Animal();
abc.makesound("dog");
Cat xyz=new Cat();
xyz.makesound();
}
}
+ 1
class Cat extends Animal {
public void makesound(){
System.out.println("meau meau");
}
}
It's "class Cat extends Animal" (line 14)
And it's "public void" (line 15). Check your spellings.
+ 1
Here is an easy example with only one class how overloading works:
https://code.sololearn.com/cggcHjdL0HEE/?ref=app
0
https://code.sololearn.com/cUnH1FzmU6lQ/?ref=app
0
I suggest you to read more about inner classes to really understand your problem:
https://www.baeldung.com/java-nested-classes
0
class animal must be static.
0
you can not call a non-static method / class inside a static method / class.