+ 1

How to use class if it is written in an extra .java file?

if i am creating a new class in an extra java file and than switch to the "main" class and try to create an object of that class it always says "unknown entity" in my mobile compiler. Do i have zo imoprt the file like the header in c++?

25th Sep 2018, 11:36 AM
Andreas Wagner
Andreas Wagner - avatar
1 Odpowiedź
0
You have to creat an instance (call) the class you want in the class where you want to use it. An example of it would be: Class1.java public class Class1 { // Your code from Class1. } Class2.java public class Class2 { private Class1 class1 = new Class1(); // Your code from class2. } Then with class1.nameOfMethod() you can use the public methods from class1 in your Class2.java file. Tell me if it works. :)
26th May 2019, 1:57 AM
Franz Lüpke
Franz Lüpke - avatar