Java using methods from diffirent .java files. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita

Java using methods from diffirent .java files.

So I have two .java, each with their own class. The first one is My.Class with the following code: [code]class MyClass { } public static void main(String[] args) { bark(); } /* SayHello(name,age); */ static void SayHello(String name, int age){ System.out.println("Hello " + name + " You are " + age + " Years old"); } } [/code] And my second class in a totally diffirent .java file. [code]class Animal { void bark() { System.out.println("Woof-Woof!"); } public static void main (String[] args) { bark(); } }[/code] Question, can I call bark() from my class? Whenever I tried it gives me this error error: cannot find symbol bark();

17th Dec 2017, 6:34 AM
Steven - avatar
1 Respuesta
use new Animal().bark();
17th Dec 2017, 7:36 AM
1of3 - avatar