Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

JAVA-ソースコードの分割(Package利用)

More than 5 years have passed since last update.

▪️test45.java ソースコード

package calcapp.main;

public class test45 {
    public static void main(String[] args) {
        int a = 10;
        int b = 2;
        int total = calcapp.logics.test47.tasu(a, b);
        int delta = calcapp.logics.test47.hiku(a, b);
        System.out.println("足すと" + total + "、引くと" + delta);
    }
}

▪️test47.java ソースコード

package calcapp.logics;

public class test47 {
    public static int tasu(int a, int b) {
        return (a + b);
    }

    public static int hiku(int a, int b) {
        return (a - b);
    }
}

▪️実行結果
足すと12、引くと8スクリーンショット 2015-10-20 14.43.04.png

▪️例①完全限定クラス名の入力を省略する
import文を使用する

▪️例① test45.java ソースコード

package calcapp.main;
import calcapp.logics.test47;

public class test45 {
    public static void main(String[] args) {
        int a = 10;
        int b = 2;
        // FQCNでなくてもエラーにならない
        int total = test47.tasu(a, b);
        // FQCNを指定しても良い
        int delta = calcapp.logics.test47.hiku(a, b);
        System.out.println("足すと" + total + "、引くと" + delta);
    }
}

▪️例① test47.java ソースコード

package calcapp.logics;

public class test47 {
    public static int tasu(int a, int b) {
        return (a + b);
    }

    public static int hiku(int a, int b) {
        return (a - b);
    }
}

▪️例① 実行結果
足すと12、引くと8

スクリーンショット 2015-10-20 15.29.10.png

icelandnono
24歳です 職場は渋谷です 渋谷興味ない。。 新橋とかで働きたい。。銀座がすき
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away