java how to use classes in other package?

后端 未结 3 451
隐瞒了意图╮
隐瞒了意图╮ 2020-12-01 14:14

can I import,use class from other package? In Eclipse I made 2 packages one is main other is second

main
 -main (class)
second
 -second (class)

and I w

3条回答
  •  没有蜡笔的小新
    2020-12-01 14:51

    Given your example, you need to add the following import in your main.main class:

    import second.second;
    

    Some bonus advice, make sure you titlecase your class names as that is a Java standard. So your example Main class will have the structure:

    package main;  //lowercase package names
    public class Main //titlecase class names
    {
        //Main class content
    }
    

提交回复
热议问题