一段有意思的代码

package ex01.pyrmont;

public class Son extends Father {
    public void a(){
        System.out.println("a from son");
        super.a();
    }

    public void b(){
        System.out.println("b from son");
    }

    public static void main(String[] args) {
        Son son=new Son();
        son.a();
    }
}
package ex01.pyrmont;

public class Father {

    public void a(){
        System.out.println("a from father");
        b();
    }

    public void b(){
        System.out.println("b from father");
    }
}

执行后会输出什么,为什么?

答案如下

a from son

a from father

b from son

如果把Son中的方法b去掉,会怎么样呢?

a from son

a from father

b from father

时间: 2024-08-02 08:48:18

一段有意思的代码的相关文章

一段比较有意思的代码——介绍system verilog中的新增幅值语句

system verilog中新加了很多幅值语句,虽然都只适用于阻塞幅值,但是在某些场合中非常实用. 下面是一段有意思的代码,覆盖了一些用法. 1 package definitions; 2 typedef enum logic [2:0] {ADD,SUB,MULT,DIV,SL,SR} opcode_t; 3 typedef enum logic {UNSIGNED, SIGNED} operand_type_t; 4 typedef union packed { 5 logic [23:

实在忍不住了,发一段神级代码,大家瞻仰瞻仰

跟这样的函数比起来,顿觉日月无光,天昏地暗,飞沙走石! 完全一派末日景象啊! 另外命名什么的就先无视吧……跟这么强大的封装比起来,命名算个屁啊! ----说下背景吧-------------- 上述代码是我强调了多次,MVC必须要用Model,然后要注意封装,结果这姐姐(工作2年多了都)就封装成这个德行了 -------------------- 同样一个函数,既能返回一个对象,还能返回这个对象中的某个属性啊服了工作这么多年第一次见这样的神级代码 .到处new,new你妹啊new! ------

c#实现每隔一段时间执行代码(多线程)

总结以下三种方法,实现c#每隔一段时间执行代码: 方法一:调用线程执行方法,在方法中实现死循环,每个循环Sleep设定时间: 方法二:使用System.Timers.Timer类: 方法三:使用System.Threading.Timer: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

Web开发者的福利 30段超实用CSS代码

1.花式连字符(&) 这个类应该在span元素里使用,并且里面包括&字符.它使用经典的serif字体和斜体来增强&符号. .amp { font-family: Baskerville, 'Goudy Old Style', Palatino, 'Book Antiqua', serif; font-style: italic; font-weight: normal;} 2.段落首字符下沉 通常,这种效果会出现在印刷媒体上,如报纸或书籍.同样,如果网页布局合理,它也可以使用在We

php中禁止单个ip与ip段访问的代码小结

1.禁止单个IP <?php //IP访问限制 if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $userip = getenv('HTTP_CLIENT_IP'); } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown

一段简单的代码告诉你什么叫内存溢出

#include <stdio.h> int FooArray[4] = {1, 1, 1, 1}; int VeryImportantValue = 7; void main() { printf("%d\n", VeryImportantValue); for (int i = 0; i <= 4; i++) { FooArray[i] = 4; } printf("%d\n", VeryImportantValue); } 这是个很简单的内存

js正则实现从一段复杂html代码字符串中匹配并处理特定信息

js正则实现从一段复杂html代码字符串中匹配并处理特定信息 问题: 现在要从一个复杂的html代码字符串(包含各种html标签,数字.中文等信息)中找到某一段特别的信息(被一对“|”包裹着),并对他进行加粗.加下滑线处理. 解决思路: 1.用正则匹配“|”出现的次数,处理刚好出现2次的(html字符串中一般不会含有这个字符) 2.使用正则分组,获取“|”之间的内容,并进行替换(添加样式) 代码: function specialDeal(){ htmlStr = htmlStr.replace

给大家看段比较有意思的代码

package code.classloader; public class Interesting { public static int count1; public static int count2 = 0; public static Interesting ins = new Interesting(); private Interesting() { count1++; count2++; } public static Interesting getInstance() { re

有意思的代码--利用系统信号切换日志模式

看到Kite里面的源码,有段代码挺有意思. 上代码先: // SetupSignalHandler listens to signals and toggles the log level to DEBUG // mode when it received a SIGUSR2 signal. Another SIGUSR2 toggles the log // level back to the old level. func (k *Kite) SetupSignalHandler() { c