00P-类和对象

 什么是类?

  类:类别,是所有具备相同属性和方法的一个表示

 什么是对象?

   对象:世万物看到的都是对象

类和对象的关系?

  类是抽象的概念,仅仅是一个模板,而对象是一个你能看得着,摸得着的实体。

 

对象的特征---属性

   对象具有的各种特性,每个对象的每个属性都有特定的值  

对象的特征---方法

   对象执行的操作

如何创建和使用对象

1:创建对象

  类名  对象名 = new 类名();

  School center = new School();

2:引用对象成员,是"."进行以下操作

  引用类的属性

  对象名.属性

 center.name = "北京中心"  

   引用类的方法

  对象名.方法名();

    center.show;

案例:


 

   public class Student {
  
      int stuNo;
     String  stuName;

 

     public void show(){
    System.out.println("学号是:"+stuNo+",姓名是:"+stuName);
     }

 

}

 

  测试版

    public class Teststudent {    

 

    public static void main(String[] args) {

 

    Student student = new   Student();
  
     student.stuNo=678;
  
     student.stuName="张三";
  
      student.show();
 
      }

 

}

 

 

  

 

    

 

posted @ 2020-05-03 12:15  小白315  阅读(864)  评论(0)    收藏  举报