首页 文章 精选 留言 我的

精选列表

搜索[Java框架],共10000篇文章
优秀的个人博客,低调大师

Java 面向对象 之 方法中内部类

http://www.verejava.com/?id=16992857876159 /** 知识点: 内部类 1. 内部类的定义 2. 内部类的优缺点 3. 外部类怎么实例化其他类的内部类 4. 方法中定义内部类 如果在方法中定义内部类,方法中的内部类要访问变量, 需要加final 关键字 5. static 声明内部类 题目:母亲怀了孕, 母亲的营养决定孩子的健康成长 思路: 1. 抽象出类 : 母亲(Mother), 孩子(Baby) 2. 找出类的关系: 孩子在母亲里面 Baby in Mother 3. 抽象出方法: 母亲吃东西 (eat) */ public class InnerClass2 { public static void main(String[] args) { //实例化母亲 Mother mother = new Mother("lucy"); //母亲吃苹果 mother.eat("苹果"); } } class Mother { private String name; private String food;//母亲吃的食物 public Mother(String name) { this.name = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } //母亲吃东西 public void eat(final String food) { this.food = food; System.out.println(this.name + " 吃了 " + this.food); class Baby { //孩子从母亲吃的东西中吸收营养 public void eat() { System.out.println("孩子从母亲吃的 " + food + " 中吸收营养"); } } //母亲吃东西的同时 孩子也吃东西 new Baby().eat(); } } http://www.verejava.com/?id=16992857876159

优秀的个人博客,低调大师

Java 面向对象 之 人吃水果

http://www.verejava.com/?id=16992850564257 /** 题目: 人可以(孩子,学生,老师) 吃 水果(苹果,葡萄,芒果,菠萝) 思路: 1. 抽象出类 : 人(Person){孩子(Baby),学生(Student)}, 水果(Fruit){苹果(Apple),葡萄(Grape),芒果(Mango)} 2. 找出类的关系: 水果 -> 人 (孩子,学生) 是 人的分类 也是人只是声明可以吃水果, 但是吃水果的具体执行者 是 (孩子,学生) (苹果,葡萄,芒果) 是 水果的分类 3. 找出属性: 孩子,学生(姓名,水果引用) 4. 找出方法: 孩子,学生都吃(eat)水果 子类->父类的转换 子类->父类后 父类引用调用子类复写的方法 作用 :解耦 也就是降低类与类之间的耦合度 提供可扩展性 */ public class Polymorphism5 { //打印人吃水果的信息 public void output(Person p) { //实例化一个苹果 和 一个葡萄 Apple apple = new Apple("红富士"); Grape grape = new Grape("黑葡萄"); Mango mango = new Mango("大芒果"); PineApple pineApple = new PineApple("菠萝"); p.eat(apple); System.out.println(p.getName() + " 吃了 " + p.getFruit().getName()); p.eat(grape); System.out.println(p.getName() + " 吃了 " + p.getFruit().getName()); p.eat(mango); System.out.println(p.getName() + " 吃了 " + p.getFruit().getName()); p.eat(pineApple); System.out.println(p.getName() + " 吃了 " + p.getFruit().getName()); } public static void main(String[] args) { Polymorphism5 test = new Polymorphism5(); //李明吃水果 test.output(new Baby("李明")); //张涛吃水果 test.output(new Student("张涛")); //郭老师吃水果 test.output(new Teacher("郭老师")); } } abstract class Person { protected Fruit fruit; protected String name; public Person(String name) { this.name = name; } public String getName() { return this.name; } public Fruit getFruit() { return this.fruit; } //声明人是可以吃水果的 public abstract void eat(Fruit fruit); } class Teacher extends Person { public Teacher(String name) { super(name); } //吃水果 public void eat(Fruit fruit) { this.fruit = fruit; } } class Baby extends Person { public Baby(String name) { super(name); } //吃水果 public void eat(Fruit fruit) { this.fruit = fruit; } } class Student extends Person { public Student(String name) { super(name); } //吃水果 public void eat(Fruit fruit) { this.fruit = fruit; } } class Fruit { private String name; public Fruit(String name) { this.name = name; } public String getName() { return this.name; } } class PineApple extends Fruit { public PineApple(String name) { super(name); } } class Apple extends Fruit { public Apple(String name) { super(name); } } class Grape extends Fruit { public Grape(String name) { super(name); } } class Mango extends Fruit { public Mango(String name) { super(name); } } http://www.verejava.com/?id=16992850564257

优秀的个人博客,低调大师

Java 面向对象 之 孩子 学生 吃 水果

http://www.verejava.com/?id=16992848300456 /** 题目: (孩子,学生) 吃 水果(苹果,葡萄,芒果,菠萝) 思路: 1. 抽象出类 : {孩子(Baby),学生(Student)}, 水果(Fruit){苹果(Apple),葡萄(Grape),芒果(Mango)} 2. 找出类的关系: 水果 -> (孩子,学生) (苹果,葡萄,芒果) 是 水果的分类 3. 找出属性: 孩子,学生(姓名,水果引用) 4. 找出方法: 孩子,学生都吃(eat)水果 子类->父类的转换 作用 :解耦 也就是降低类与类之间的耦合度 提供可扩展性 */ public class Polymorphism4 { public static void main(String[] args) { //实例化一个Baby Baby baby = new Baby("李明"); //实例化一个学生 Student stu = new Student("张涛"); //实例化一个苹果 和 一个葡萄 Apple apple = new Apple("红富士"); Grape grape = new Grape("黑葡萄"); Mango mango = new Mango("大芒果"); PineApple pineApple = new PineApple("菠萝"); //李明吃水果 baby.eat(apple); System.out.println(baby.getName() + " 吃了 " + baby.getFruit().getName()); baby.eat(grape); System.out.println(baby.getName() + " 吃了 " + baby.getFruit().getName()); baby.eat(mango); System.out.println(baby.getName() + " 吃了 " + baby.getFruit().getName()); baby.eat(pineApple); System.out.println(baby.getName() + " 吃了 " + baby.getFruit().getName()); //张涛吃水果 stu.eat(apple); System.out.println(stu.getName() + " 吃了 " + stu.getFruit().getName()); stu.eat(grape); System.out.println(stu.getName() + " 吃了 " + stu.getFruit().getName()); stu.eat(mango); System.out.println(stu.getName() + " 吃了 " + stu.getFruit().getName()); stu.eat(pineApple); System.out.println(stu.getName() + " 吃了 " + stu.getFruit().getName()); } } class Baby { private Fruit fruit; private String name; public Baby(String name) { this.name = name; } public String getName() { return this.name; } public Fruit getFruit() { return this.fruit; } //吃水果 public void eat(Fruit fruit) { this.fruit = fruit; } } class Student { private Fruit fruit; private String name; public Student(String name) { this.name = name; } public String getName() { return this.name; } public Fruit getFruit() { return this.fruit; } //吃水果 public void eat(Fruit fruit) { this.fruit = fruit; } } class Fruit { private String name; public Fruit(String name) { this.name = name; } public String getName() { return this.name; } } class PineApple extends Fruit { public PineApple(String name) { super(name); } } class Apple extends Fruit { public Apple(String name) { super(name); } } class Grape extends Fruit { public Grape(String name) { super(name); } } class Mango extends Fruit { public Mango(String name) { super(name); } } http://www.verejava.com/?id=16992848300456

优秀的个人博客,低调大师

Java 面向对象 之 final 关键字

http://www.verejava.com/?id=16992827836151 /** 知识点: final 关键字 1. 什么是final : final 就是最终的意思 2. final 关键字修饰的变量是常量 不能修改 3. final 关键字修饰的方法,子类不能复写 4. final 关键字修饰的类,不能被继承 */ public class FinalKeyword { public static void main(String[] args) { final double PI = 3.14; System.out.println(PI); //实例化父亲 Father f = new Father(); f.work(); //实例化儿子 Son s = new Son(); s.study(); } } //父亲 class Father { public final void work() { System.out.println("干农活"); } } //儿子 class Son extends Father { public void study() { System.out.println("好好学习,天天向上"); } } //女儿 final class Daughter extends Father { } //孙子 class GranSon extends Son { } http://www.verejava.com/?id=16992827836151

优秀的个人博客,低调大师

Java 面向对象 之 super 关键字

http://www.verejava.com/?id=17159596599630 /** this: 代表当前类的引用 1. 当局部变量和成员变量同名时, 成员变量要加 this 限定 2. 实例化时 可以用 this 调用当前类的构造方法, 必须写在第一行 3. 可以用 this 调用当前类的 普通方法 super : 代表当前父类的引用 1. 实例化子类时, 可以用 super 调用父类的 非私有方法 2. 实例化子类时. 可以用 super 调用父类的 构造方法 , 必须写在第一行 3. 在子类的方法中 , 可以用 supe 调用父类的 非私有方法. */ public class Test1 { public static void main(String[] args) { // 实例化 农夫 Father father = new Father(); father.setName("农夫"); father.setAge(90); System.out.println(father.getAge() + " 岁 " + father.getName() + " 有 " + father.getWealth()); Father father = new Father("农夫", 90); System.out.println(father.getAge() + " 岁 " + father.getName() + " 有 " + father.getWealth()); Son son = new Son("农夫", 90); System.out.println("儿子知道父亲的 : " + son.getAge() + " 岁 " + son.getName() + " 有 " + son.getWealth()); son.work(); } } //父类 class Father { private String name; private int age; private String wealth; public Father() { wealth = "100两黄金"; } public Father(String name, int age) { this(); this.name = name; //this.age=age; this.setAge(90); } public void work() { System.out.println("耕地"); } public String getWealth() { return wealth; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } public void setName(String name) { this.name = name; } public String getName() { return name; } } //子类 class Son extends Father { public Son(String name, int age) { super(name, age); //super.setName(name); //super.setAge(age); } public void work() { super.work(); System.out.println("儿子 寻找黄金宝藏"); System.out.println("只有通过自己的勤奋劳动, 才能得到果实 是最大的宝藏"); } } http://www.verejava.com/?id=17159596599630

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码