• 极客教程--Java基础内容(完结)


    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(){
                System.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 interface 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();
        }
    
    }
    
    

    我曾七次鄙视自己的灵魂:
    第一次,当它本可进取时,却故作谦卑;
    第二次,当它在空虚时,用爱欲来填充;
    第三次,在困难和容易之间,它选择了容易;
    第四次,它犯了错,却借由别人也会犯错来宽慰自己;
    第五次,它自由软弱,却把它认为是生命的坚韧;
    第六次,当它鄙夷一张丑恶的嘴脸时,却不知那正是自己面具中的一副;
    第七次,它侧身于生活的污泥中,虽不甘心,却又畏首畏尾。
  • 相关阅读:
    天生我材必有用?
    峨眉山徒步之行
    S3C6410 GPIO操作接口
    工作
    奖金
    吝啬的地主
    聪明的小李
    地铁重组
    灵魂分流药剂
    摆渡线路
  • 原文地址:https://www.cnblogs.com/meditation5201314/p/14852476.html
Copyright © 2020-2023  润新知