zoukankan      html  css  js  c++  java
  • 创建对象数组,给数组赋值(两种理解思路)

    创建对象数组,给数组赋值(两种理解思路)

    class Student{
         String name;
         int  age;
    }
    public class StudentTest{
        Student  []stu=new Student[5];//创建学生对象数组(其中的元素是类的一个对象)
        Student demo=new Student();   //创建一个学生类的对象
        demo.name="张三";
        demo.age=18;    //给对象的属性赋值
        stu[0]=demo;    //将对象demo赋值给对象数组的一个位置的值
        System.out.println(stu[0].name) 
    }
    
    
    class Student{
         String name;
         int  age;
    }
    public class StudentTest{
        Student  []stu=new Student[5];      //创建学生对象数组(其中的元素是类的一个对象)
       stu[0]=new student; //实例化
    stu[0].name="张三"; //给元素(一个对象)的属性赋值
    stu[0].age=18;
    System.out.println(stu[0].name) }
     
  • 相关阅读:
    学习第23天
    学习第22天
    学习第21天
    Servlet交互与JSP
    Cookie与Session
    servlet入门
    网络编程
    DOM4j
    xml文档对象模型doc
    反射
  • 原文地址:https://www.cnblogs.com/xiao-ran/p/9797268.html
Copyright © 2011-2022 走看看