萌新学Java
冲啊
「已注销」
这个作者很懒,什么都没留下…
展开
-
多态,抽象类,接口
人类 public abstract class Person { private String name; private int age; public Person() { } public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name;原创 2020-09-28 16:21:19 · 128 阅读 · 0 评论 -
修饰符,关键字
权限修饰符 finall static 静态成员方法只能访问静态成员 class Student { public String name; //姓名 public int age; //年龄 public static String university; //学校 共享数据!所以设计为静态! public void show() { System.out.println(name + "," + age + "," + university);原创 2020-09-27 18:59:32 · 117 阅读 · 0 评论 -
继承
关键字 this(…) - 访问本类构造方法 super(…) - 访问父类构造方法 方法重写 私有方法不能被重写(父类私有成员子类是不能继承的) 子类方法访问权限不能更低(public > 默认 > 私有) 动物和猫 public class Animal { private String name; private int age; public Animal() { } public Animal(String name, int age)原创 2020-09-27 18:59:09 · 58 阅读 · 0 评论 -
学生管理代码
学生类 package SYS_pck; public class Student { private String sid; private String name; public Student() { } public Student(String sid, String name, String age, String address) { this.sid = sid; this.name = name; }原创 2020-09-26 20:01:19 · 482 阅读 · 0 评论 -
API
String 创建 String s1 = new String(); char[] chs = {‘a’, ‘b’, ‘c’}; String s2 = new String(chs); byte[] bys = {97, 98, 99}; String s3 = new String(bys); String s4 = “abc”; 通过构造方法创建 通过 new 创建的字符串对象,每一次 new 都会申请一个内存空间,虽然内容相同,但是地址值不同 直接赋值方式创建 以“”方式给出的字符串,只要字符序列原创 2020-09-26 19:43:06 · 71 阅读 · 0 评论 -
类方法
Random 1:导包 import java.util.Random; 2:创建对象 Random r = new Random(); 3:获取随机数 int number = r.nextInt(10); 获取数据的范围:[0,10) 包括0,不包括10 输入 字符串 Scanner sc = new Scanner(System.in); String s = sc.nextLine(); 数字 Scanner sc = new Scanner(System.in);原创 2020-09-26 19:55:55 · 45 阅读 · 0 评论 -
类对象
class Student { //成员变量 private String name; private int age; //构造方法 public Student() { } public Student(String name, int age) { this.name = name; this.age = age; } //成员方法 public void setName(String name) { this.name = name; } public String getName() { retu原创 2020-09-26 19:40:03 · 131 阅读 · 0 评论 -
方法
内存 重载原创 2020-09-26 19:52:38 · 59 阅读 · 0 评论 -
语句结构
switch switch(month) { case 1: case 2: case 12: System.out.println("冬季"); break; case 3: case 4: case 5: System.out.println("春季"); break; case 6: case 7: case 8: System.out.println("夏季"); break; case 9:原创 2020-09-26 19:53:45 · 76 阅读 · 0 评论 -
运算符
三元 int a = 10; int b = 20; //max必须和ab同类 int max = a > b ? a : b; 自加 //注意:扩展的赋值运算符底层隐含了强制类型转换 short s = 10; s += 20; //s = (short)(s + 20); 短路 System.out.println((i > j) & (i > k)) System.out.println((i > j) && (i >原创 2020-09-26 19:54:51 · 52 阅读 · 0 评论 -
类型转换
byte b1 = 10; byte b2 = 20; byte b3 = b1 + b2; // 第三行代码会报错,b1和b2会自动转换为int类型,计算结果为int,int赋值给byte需要强制类型转换。 // 修改为: int num = b1 + b2; // 或者: byte b3 = (byte) (b1 + b2); //注意:扩展的赋值运算符底层隐含了强制类型转换 short s = 10; s += 20; //s = (short)(s + 20); boolean类..原创 2020-09-26 19:55:25 · 69 阅读 · 0 评论