+ 1
Public Class Animal Cannot Be Accesed
Public Class AnImal Cannot Be Accessed By Main Class if They are Written In Same Java Prog.
7 Respuestas
+ 3
please show your code so that you can get the appropriate help you need
+ 2
It is not clear from your question that what are you trying to ask. But to use a method of a class, you need to create an object of it and then you can invoke that method.
https://www.sololearn.com/learn/Java/2155/
+ 2
The code works without a problem for me:
https://code.sololearn.com/c55GZ7HcZjEO/?ref=app
+ 2
Garvit Joshi Just see whether your main class is also public in that case because java cannot have two public classes in a single file since the public class has to be the source file name then if you declare two public classes then there's ambiguity in choosing a single class as file name.
+ 1
public class Animal {
void bark() {
System.out.println("Woof-Woof");
}
}
class MyClass {
public static void main(String[ ] args) {
Animal dog = new Animal();
dog.bark();
}
}
+ 1
This Code Is In Solo Learn In Java Class Section.