首页 > 其他 > 详细

静态修饰符static

时间:2021-02-19 17:12:28      阅读:26      评论:0      收藏:0      [点我收藏+]

静态修饰符static

使用与不使用的区别

建议少使用静态修饰符

使用

  1. 与类一起加载,只要类被装载进程序中,该方法一起被加载完成。

    使用举例

    //使用静态修饰符
    public class Student
    {
        public static void say()
        {
            System.out.println("hello world!");
            return;
        }
    }
    //调用
    import Student
    ‘‘‘
        pubilc static void main(String[] args)
    {
        Student.say();
    }
    //预期输出结果
    hello world!
    

不使用

  1. 当类被实例化以后才能使用该方法。

    使用举例

    //不使用静态修饰符
    public class Student
    {
        public void say()
        {
            System.out.println("hello world!");
            return;
        }
    }
    //调用
    import Student
    ‘‘‘
        pubilc static void main(String[] args)
    {
        Student student = new Student();
        student.say();
    }
    //预期输出结果
    hello world!
    

静态修饰符static

原文:https://www.cnblogs.com/wing-of-dream/p/14416203.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!