极客教程--Java基础内容(完结)
2021-06-05 12:25
274 查看
Java--基础内容(完结)
之前有赞笔试题基础题挂了,还是得承认自己基础很垃圾,要多补补,不能只搞框架。精通基础,结合设计模式,以后能走得更远
极客教程--参考链接:https://geek-docs.com/java/java-tutorial/super-keyword-in-java-with-example.html
Java
Java特性 抽象:子类要实现父类所有方法
封装:类封装属性
继承:子类拥有父类所有能力,并且可以拓展,实现多态效果
多态:多态允许您定义一个接口并具有多个实现
super关键字
子类 new 的时候,需要调用父类的构造方法,也可以用super访问父类变量和父类构造函数
重载与重写
overload:类中函数名相同,但是参数和返回值不同 override:子类继承父类:对父类方法的重写
接口与抽象类
父类 = new 子类:只能使用子类继承过来的方法,且方法是子类的 抽象类:所有继承的子类必须实现父类中所有抽象类方法,且为public 接口中可以包含抽象类,A类不能多重继承实现多种功能,但是可以通过多重实现接口来实现多种功能
垃圾回收:
垃圾回收堆内存,当对象 = null(不可达),或者引用obj1 = 引用obj2时就要垃圾回收
package com.empirefree.springboot; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.omg.CORBA.PUBLIC_MEMBER; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.awt.*; /** * @program: springboot * @description: Java基础 * @author: huyuqiao * @create: 2021/06/05 10:14 */ @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class JavaTest { /* * 子类new,先调用父类的构造方法 * */ class Parentclass { int num = 100; //no-arg constructor Parentclass(){ Sys 56c tem.out.println("no-arg constructor of parent class"); } //arg or parameterized constructor Parentclass(String str){ System.out.println("parameterized constructor of parent class"); } void display(){ System.out.println("Hello"); } } class Subclass extends Parentclass { Subclass(){ /* super() must be added to the first statement of constructor * otherwise you will get a compilation error. Another important * point to note is that when we explicitly use super in constructor * the compiler doesn't invoke the parent constructor automatically. */ // super("Hahaha"); System.out.println("Constructor of child class"); System.out.println(super.num); } } abstract class AbstractDemo{ public void myMethod(){ System.out.println("hello"); } abstract public void anotherMethod() throws Exception; void test(){ System.out.println("asdf"); } } public class Demo extends AbstractDemo{ public void anotherMethod() throws Exception { System.out.println("Abstract method"); throw new MyException("抛出异常。。。"); } } public interface Inf1{ } public i 56c nterface Inf2 extends Inf1{ } //自定义异常 class MyException extends Exception{ MyException(String str2) { System.out.println("asdfs"); } } public class SimpleExample extends Frame{ SimpleExample(){ //玩玩awt Button button = new Button("button"); button.setBounds(50, 50, 50, 50); add(button); setSize(500, 300); setTitle("this is my first awt example"); setLayout(new FlowLayout()); setVisible(true); } } @Test public void testParentAndChildren() throws Exception { /* Subclass obj= new Subclass(); obj.display();*/ /* 父类 = new 子类:只能使用子类继承过来的方法,且方法是子类的 抽象类:所有继承的子类必须实现父类中所有抽象类方法 */ /* AbstractDemo abstractDemo = new Demo(); abstractDemo.anotherMethod(); abstractDemo.test();*/ System.setProperty("java.awt.headless", "false"); SimpleExample simpleExample = new SimpleExample(); } }
相关文章推荐
- Java基础教程41-读取文件内容
- 史上最简单的spark教程第六章-键值对RDD聚合,分组,统计的Java案例实践-(下集)[核心基础完结篇章]
- Java Web Start入门基础教程
- Java Web Start入门基础教程 2
- 黑马程序员_毕向东_Java基础视频教程第十八天-IO流---学习笔记
- Java Web Start 入门基础教程
- Java Servelet API入门基础教程
- java nio基础教程
- Java基础教程 02
- java基础教程-类
- Java Media Framework 基础教程
- java基础教程之异常
- 学习java基础教程收获一
- 毕向东_Java基础视频教程-第01天-环境配置之Path和classpath
- 黑马程序员_Java基础_常用基础内容(进制转换、基本数据类型、运算符、流程控制语句等)
- 变态级的JAVA程序员面试32问(很多都是基础内容)
- web service的基础教程 web Service java
- java基础教程-继承
- java基础教程-JDBC数据库访问技术
- Java Media Framework 基础教程(二)