Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (7k points)
How to import a class in another file of the same package?

1 Answer

0 votes
by (13.1k points)

If the custom class is in same then there is no need to import, you can just instantiate it like this:

className object=new className();

If the custom class is in a different class then you have to import it like this:

import packagename.className;

And instantiate using:

Classname className=new className()

Want to learn Java? Check out the Java course from Intellipaat.

Related questions

0 votes
1 answer
asked Apr 14, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...