【java】使用IDEA进行 java调用类

在IDEA中新建项目project

Main.java

package com.company;

public class Main {

    public static void main(String[] args) {
	// write your code here
        System.out.println("Hello world");

        test test1 = new test();
        test1.prin();
        test1.apped();
        test1.apped();
        test1.apped();
        DataType data1 = new DataType();
        data1.type();
    }
}

新建两个java

test.java

package com.company;

public class test {
    int i = 0;
    public void prin(){
        System.out.println("test");
    }
    public void apped(){
        i++;
        System.out.println("apped:"+i);
    }
}

DataType.java

package com.company;

public class DataType {
    static boolean bool;
    static byte by;
    static char ch;
    static float f;
    static double d;
    static int i;
    static long l;
    static short sh;
    static String str;
    public static void type(){
        System.out.println("Bool :"+bool);
        System.out.println("Byte :"+by);
        System.out.println("Character:"+ch);
        System.out.println("Double :"+d);
        System.out.println("Float :"+f);
        System.out.println("Integer :"+i);
        System.out.println("Long :" +l);
        System.out.println("Short :"+sh);
        System.out.println("String :"+str);

    }
}

结果

Hello world
test
apped:1
apped:2
apped:3
Bool :false
Byte :0
Character: 
Double :0.0
Float :0.0
Integer :0
Long :0
Short :0
String :null

Process finished with exit code 0
发布了201 篇原创文章 · 获赞 46 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/rong11417/article/details/105015645