笔试笔记9.5

1.父类与子类构造顺序问题

代码如下:

public class Main {
    public static void main(String[] args) {
       Father father = new Child();
    }
}

class Father {
    static {
        System.out.println("Father static area");
    }

    {
        System.out.println("Father dynamic area");
    }

    Father() {
        System.out.println("Father Constructor");
    }
}

class Child extends Father{
    static {
        System.out.println("Child static area");
    }

    {
        System.out.println("Child dynamic area");
    }

    Child() {
        System.out.println("Child Constructor");
    }
}

输出结果为:

Father static area
Child static area
Father dynamic area
Father Constructor
Child dynamic area
Child Constructor

从输出结果可以看出执行顺序为:
- 父类静态代码块
- 子类静态代码块
- 父类动态代码块
- 父类构造函数
- 子类动态代码块
- 子类构造函数

2.函数参数重载

public class Help {
    public static void main(String[] args) {
       Father father = new Child();
       Help help = new Help();
       help.method(father);
    }

    public void method(Father father) {
        System.out.println("This is father");
    }

    public void method(Child child) {
        System.out.println("This is child");
    }

    public void method(InterFace interFace) {
        System.out.println("This is InterFace");
    }


}

class Father {

}

interface InterFace {

}

class Child extends Father implements InterFace {

}

根据引用类型进入相应的方法

This is father

3.子类成员变量是否可以覆盖父类成员变量

public class Help {
    protected int a = 0;

    public static void main(String[] args) {
        Help help = new Help();
        InnerClass innerClass = help.new InnerClass();
        System.out.println(innerClass.a);
    }

    public class InnerClass extends Help {
        protected int a = 1;
    }
}
1

结果是可以覆盖的

4.try -> catch -> finally的执行顺序问题

/**
 * Created by dly on 2018/9/5
 */
public class TestException {
    public TestException() {
    }

    boolean testEx() throws Exception {
        boolean ret = true;
        try {
            ret = testEx1();
        } catch (Exception e) {
            System.out.println("testEx, catch exception");
            ret = false;
            throw e;
        } finally {
            System.out.println("testEx, finally; return value=" + ret);
            return ret;
        }
    }

    boolean testEx1() throws Exception {
        boolean ret = true;
        try {
            ret = testEx2();
            if (!ret) {
                return false;
            }
            System.out.println("testEx1, at the end of try");
            return ret; //try遇到return会跳转到finally
        } catch (Exception e) {
            System.out.println("testEx1, catch exception");
            ret = false;
            throw e;
        } finally {
            System.out.println("testEx1, finally; return value=" + ret);
            return ret;
        }
    }

    boolean testEx2() throws Exception {
        boolean ret = true;
        try {
            int b = 12;
            int c;
            for (int i = 2; i >= -2; i--) {
                c = b / i;
                System.out.println("i=" + i);
            }
            return true;
        } catch (Exception e) {
            System.out.println("testEx2, catch exception");
            ret = false;
            throw e;    //往finally跳转, throw未执行,异常会被直接屏蔽
        } finally {
            System.out.println("testEx2, finally; return value=" + ret);
            return ret;
        }
    }

    public static void main(String[] args) {
        TestException testException1 = new TestException();
        try {
            testException1.testEx();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

执行结果

i=2
i=1
testEx2, catch exception
testEx2, finally; return value=false
testEx1, finally; return value=false
testEx, finally; return value=false
分数阶傅里叶变换(Fractional Fourier Transform, FRFT)是对传统傅里叶变换的拓展,它通过非整数阶的变换方式,能够更有效地处理非线性信号以及涉及时频局部化的问题。在信号处理领域,FRFT尤其适用于分析非平稳信号,例如在雷达、声纳和通信系统中,对线性调频(Linear Frequency Modulation, LFM)信号的分析具有显著优势。LFM信号是一种频率随时间线性变化的信号,因其具有宽频带和良好的时频分辨率,被广泛应用于雷达和通信系统。FRFT能够更精准地捕捉LFM信号的时间和频率信息,相比普通傅里叶变换,其性能更为出色。 MATLAB是一种强大的数值计算和科学计算工具,拥有丰富的函数库和用户友好的界面。在MATLAB中实现FRFT,通常需要编写自定义函数或利用信号处理工具箱中的相关函数。例如,一个名为“frft”的文件可能是用于执行分数阶傅里叶变换的MATLAB脚本或函数,并展示其在信号处理中的应用。FRFT的正确性验证通常通过对比变换前后信号的特性来完成,比如评估信号的重构质量、信噪比等。具体而言,可以通过计算原始信号与经过FRFT处理后的信号之间的相似度,或者对比LFM信号的关键参数(如初始频率、扫频率和持续时间)是否在变换后得到准确恢复。 在MATLAB代码实现中,通常包含以下步骤:首先,生成LFM信号模型,设定其初始频率、扫频率、持续时间和采样率等参数;其次,利用自定义的frft函数对LFM信号进行分数阶傅里叶变换;接着,使用MATLAB的可视化工具(如plot或imagesc)展示原始信号的时域和频域表示,以及FRFT后的结果,以便直观对比;最后,通过计算均方误差、峰值信噪比等指标来评估FRFT的性能。深入理解FRFT的数学原理并结合MATLAB编程技巧,可以实现对LFM信号的有效分析和处理。这个代码示例不仅展示了理论知识在
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值