随笔分类 -  Java学习笔记

摘要:13_内部类 太难了。 阅读全文
posted @ 2024-07-02 22:02 神莹 阅读(7) 评论(0) 推荐(0)
摘要:12_接口 只有规范,自己无法写方法(专业的约束) 定义一些方法,让不同的人实现 方法默认public abstract 常量默认public static final 接口不能实例化,没有构造方法 可以实现多个接口,实现接口必须重写里面的方法 //接口都需要有实现类 public interfac 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(19) 评论(0) 推荐(0)
摘要:11_抽象类 抽象类 public abstract class Action { //抽象方法,只有方法名字,没有方法实现 public abstract void dosomething(); } //继承抽象类必须实现抽象方法,除非它也是抽象类 public class A extends A 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(19) 评论(0) 推荐(0)
摘要:10_static详解 public class Person { { System.out.println("匿名代码块"); } static{ System.out.println("静态代码块"); } public Person(){ System.out.println("构造方法"); 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(16) 评论(0) 推荐(0)
摘要:09_instanceof关键字和类型转换 instanceof用于判断对象和类的关系是否为父子 //Object>String //Object>Person>Teacher //Object>Person>Student Object object = new Student();//引用obj 阅读全文
posted @ 2024-07-02 22:01 神莹 阅读(21) 评论(0) 推荐(0)
摘要:08_多态 public class Application { public static void main(String[] args) { Student s1 = new Student(); Person s2 = new Student(); Object s3 = new Stude 阅读全文
posted @ 2024-07-02 22:00 神莹 阅读(17) 评论(0) 推荐(0)
摘要:07_方法的重写 子类重写父类的方法 静态方法等级较高,不算重写 public class Application { public static void main(String[] args) { A a = new A(); a.test();//Atest //父类B的引用指向子类A B b 阅读全文
posted @ 2024-07-02 22:00 神莹 阅读(25) 评论(0) 推荐(0)
摘要:06_super super super必须只能出现在子类的方法或子类的构造方法中! super调用父类构造方法,必须在构造方法的第一个 super和this不能同时调用构造方法! public class Application { public static void main(String[] 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(36) 评论(0) 推荐(0)
摘要:05_继承 extends public class Person { private int money = 10_0000_0000; } public class Student extends Person{ } public class Teacher extends Person{ } 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(18) 评论(0) 推荐(0)
摘要:04_封装 程序追求高内聚,低耦合 属性私有,get/set public class Student { private String name; private int age; private char gender; public String getName() { return this 阅读全文
posted @ 2024-07-02 21:59 神莹 阅读(22) 评论(0) 推荐(0)
摘要:03_创建对象的内存分析 栈存变量,后进先出;堆存对象,先进先出。 阅读全文
posted @ 2024-07-02 21:58 神莹 阅读(16) 评论(0) 推荐(0)
摘要:02_类和对象 一个类即使什么都不写也会存在一个构造方法 //默认构造方法 public class Student { public Student() { } } 2.显示的定义构造器 public class Person { String name; //无参构造 public Person 阅读全文
posted @ 2024-07-02 21:58 神莹 阅读(16) 评论(0) 推荐(0)
摘要:01_面向对象 以类的方式组织代码,以对象方式封装数据 三大特性:封装,继承,多态 静态方法和非静态方法 //静态方法,和类一起加载 public static void a(){ } //非静态方法,类实例化之后才存在 public void b(){ } 值传递 public static vo 阅读全文
posted @ 2024-07-02 21:57 神莹 阅读(15) 评论(0) 推荐(0)
摘要:06_稀疏数组 当一个数组中大部分元素为0或为同一值时,可以使用稀疏数组保存该数组。 //创建一个11*11的二维数组,0没有棋子,1黑棋,2白棋 int[][] array = new int[11][11]; array[1][2] = 1; array[2][3] = 2; System.ou 阅读全文
posted @ 2024-07-01 22:19 神莹 阅读(23) 评论(0) 推荐(0)
摘要:05_冒泡排序 4 3 2 1 1 4 3 2 1 2 4 3 1 2 3 4 public static void bubble_sort(int[] arr) { for (int j = 0; j < arr.length - 1; j++) { for (int i = arr.length 阅读全文
posted @ 2024-07-01 22:18 神莹 阅读(17) 评论(0) 推荐(0)
摘要:04_Arrays类 int[] arr = {1,2,3,4,5,6,7,8,9,10}; Arrays.sort(arr); System.out.println(Arrays.toString(arr)); 阅读全文
posted @ 2024-07-01 22:18 神莹 阅读(15) 评论(0) 推荐(0)
摘要:03_数组 声明数组,开辟数组内存,数组赋值 //动态初始化 int[]nums = new int[5]; //静态初始化 int[]nums = {1,2,3,4,5}; 二维数组 //[4,2]4行两列数组 //动态初始化 int[][]array = new int[4][2]; //静态初 阅读全文
posted @ 2024-07-01 22:17 神莹 阅读(23) 评论(0) 推荐(0)
摘要:02_简单计算器实现 public class Demo { public static void main(String[] args) { int flag = 0; while(flag != 5){ System.out.println("选择加法请按1,2,3,4"+"\t"+"退出请按5 阅读全文
posted @ 2024-07-01 22:17 神莹 阅读(18) 评论(0) 推荐(0)
摘要:01_递归 求n! public static int f(int n){ if(n==1){ return 1; }else{ return n*f(n-1); } } 阅读全文
posted @ 2024-07-01 22:16 神莹 阅读(27) 评论(0) 推荐(0)
摘要:04_打印三角形 for (int i = 1; i <= 10; i++) { for (int j = 10; j >= i; j--) { System.out.print(" "); } for (int j = 1; j <= i; j++) { System.out.print("*") 阅读全文
posted @ 2024-06-30 20:03 神莹 阅读(25) 评论(0) 推荐(0)