0

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. Animal.java [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 myclass.java:7: error: cannot find symbol bark();

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