静态初识

本文提供了一个使用Java编程语言创建的简单示例,包括定义Person类、数学工具类Shuxue及学生类Student。示例展示了静态变量、静态方法、构造函数等概念,并通过主函数进行了实例演示。
package Jing;

public class Person {
String name;
static String history="5000年前是猴纸";


    
    
    
}
package Jing;

public class Shuxue {

public final static double PI=3.14;

public static boolean isPrime(int a){
    for(int i=2;i<=a;i++){
        if(i==a){
            return true;
            
        }
        if(a%i==0){
            return false;
        }
    }
    return false;
}
}
package Jing;

public class Student {
    private static int count=1000;
    int sno;
    //String sno
    String name;
    public Student(String name) {
        super();
        sno=++count;
        //++count
        //sno="hit00"+count
        this.name = name;
    }
    public void showInfo(){
        System.out.println("学号"+sno+"姓名"+name);
    }

}
package Jing;

public class TestPerson {

    public static void main(String[] args) {

Person p=new Person();
p.name="张飞";
System.out.println(Person.history);
p.history="10000年前还是猴子";
Person p1=new Person();
p1.name="王权";
System.out.println(p1.history);
System.out.println(Shuxue.PI);
System.out.println(Shuxue.isPrime(12));

for(int i=0;i<10;i++){
    Student s=new Student("张飞"+i);
    s.showInfo();
}

    }

}

 

转载于:https://www.cnblogs.com/zyy1130/p/6704243.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值