美文网首页
关于JAVA类 对象 方法 理解

关于JAVA类 对象 方法 理解

作者: 3de6c44e93f3 | 来源:发表于2017-04-01 13:09 被阅读0次
    • 类:如public class xxx {}
    • 对象的创建:

    如: Scanner in = new Scanner(System.in);
    拆分: Scanner in; //对象声明
    in = new Scanner(System.in); //创建对象
    System.in //获取键盘输入信息

    • 对象的使用:

    对象.成员变量
    对象.成员方法()
    如:int number=in.nexttInt(); //调用nextInt方法

    • 方法(实例)例子:
    public class Point{
        int add(int a,int b){   //实例方法
        return a+b;
        }
        static void run(){      //类方法
            ...
        }
    }
    

    使用:
    Point sum=new point(); //声明并创建对象
    int a=1,b=2;
    int sum=sum.add(a,b); //调用add方法

    实例方法与类方法区别:

    1.使用对象方法调用实例方法
    2.使用类名调用类方法
    大概区别于:Point.run();//可以直接通过类调用

    相关文章

      网友评论

          本文标题:关于JAVA类 对象 方法 理解

          本文链接:https://www.haomeiwen.com/subject/bqsiottx.html