In the context of the following code:
Package a;
public class c {
// ...
}
Package d;
public class a {
public class c {
// ...
}
}
When I use ‘a.c’ to declare and instantiate an object
a.c my_var = new a.c()
Android Studio is recognizing the class ‘c’ from package ‘d’. However, I intend to access the class ‘c’ from package ‘a’. How can I achieve this without needing to change the package names or class names?
2
Answers
You can achieve this by importing the class c from the package d into the package a. To do this, add the following import statement to the top of the class file in the package a
import d.c;
Continuing from the comment, let’s consider a real world scenario (using a, c, d… can be tough and misleading):
If you want to create an instance of the Lion class from com;example.animals and there is a Lion class in com.example.zoo package, you can do something like: