public class StudentDemo {
public static void main(String[] args) {
//如何调用构造方法呢?
//通过new关键字调用
//格式:类名 对象名 = new 构造方法(...);
Student s = new Student();
}
}
第八天:
3.3.1.1案例代码十五:
package com.itheima_03;
/*
* StringBuilder和String的相互转换
*
* StringBuilder -- String
* public String toString():通过toString()就可以实现把StringBuilder转成String
*
* String -- StringBuilder
* StringBuilder(String str):通过构造方法就可以实现把String转成StringBuilder
*/
public class StringBuilderTest {
public static void main(String[] args) {
//StringBuilder -- String
/*
StringBuilder sb = new StringBuilder();
sb.append("hello").append("world");
String s = sb.toString();
System.out.println(s);
*/
//String -- StringBuilder
String s = "helloworld";
StringBuilder sb = new StringBuilder(s);
System.out.println(sb);
}
}
第九天:
package com.itheima;
/*
* 创建一个学生数组,存储三个学生对象并遍历
*
* 分析:
* A:定义学生类
* B:创建学生数组
* C:创建学生对象
* D:把学生对象作为元素赋值给学生数组
* E:遍历学生数组
*/
public class StudentDemo {
public static void main(String[] args) {
//创建学生数组
Student[] students = new Student[3];
//创建学生对象
Student s1 = new Student("曹操",40);
Student s2 = new Student("刘备",35);
Student s3 = new Student("孙权",30);