JavaSE8基础 final 最终类,就不能作为其他类的父类(基类)

os :windows7 x64
    jdk:jdk-8u131-windows-x64
    ide:Eclipse Oxygen Release (4.7.0)
    
    
代码:

/*
	final 修饰类。
		这个类是最终类,就不能作为其他类的父类(基类)了
*/

final class Father {

}

class Son extends Father{

}

class Demo {
	public static void main(String[] agrs) {

	}
}

结果:



Java优秀,值得学习。
学习资源:itcast视频库。如果您有公开的资源,可以分享给我的话,用您的资源学习也可以。
博文是观看视频后,融入思考写成的。博文好,是老师讲得好。博文坏,是 给最苦 没认真。
如果您觉得博文有可以改进的地方,留言即可。

时间: 2024-08-28 19:21:20

JavaSE8基础 final 最终类,就不能作为其他类的父类(基类)的相关文章

C++:派生类的默认构造函数和拷贝构造函数调用基类构造函数的机制(含程序验证)

1.如果基类定义了不带参数的默认构造函数,则编译器为派生类自动生成的默认构造函数会调用基类的默认构造函数. 2.如果基类定义了拷贝构造函数,则编译器为派生类自动生成的拷贝构造函数同样会调用基类的拷贝构造函数. 3.如果基类定义了带参数的构造函数,派生类没有定义任何带参数的构造函数,则不能直接调用基类的带参构造函数,程序编译不通过. 代码如下: #include<iostream> using namespace std; //基类Game,定义了两个构造函数和一个拷贝构造函数 class Ga

asp.net 的page 基类页面 做一些判断 可以定义一个基类页面 继承Page类 然后重写OnPreLoad事件

public class BasePage:Page protected override void OnPreLoad(EventArgs e){     base.OnPreLoad(e);     .................. } 这样 就可以在基类页面 统一做一些判断了

JavaSE8基础 final修饰类的成员变量,其只可以被访问,不能被修改

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* final 修饰类的成员变量. 这个变量可以被访问,但是不能被修改.因为这个变量相当于常量. */ class Son { public final int num = 1; } class Demo { public static void main(String[] agrs) { Son s =

JavaSE8基础 final 修饰类中的成员方法 不能被子类重写

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* final 修饰类中的成员方法. 这个方法就不能被子类重写了 */ class Father { public final void show() { } } class Son extends Father{ public void show() { } } class Demo { public s

JavaSE8基础 final 修饰值类型的局部变量 其值不可更改

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* * final 修饰值类型的局部变量. */ class Demo { public void test() { final int num = 1; num = 2;//会报错! } public static void main(String[] agrs) { } } 结果: Java优秀,值得学

JavaSE8基础 final 修饰引用类型的局部变量 地址值不能变

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: /* * final 修饰引用类型的局部变量. * 引用类型是地址值,地址值不能变! */ class Test { public int num = 1; } class Demo { public void test() { final Test t = new Test(); System.out.pr

JavaSE8基础 同一个包下的子类,可以访问到父类中的 默认/受保护/公有方法

os :windows7 x64    jdk:jdk-8u131-windows-x64    ide:Eclipse Oxygen Release (4.7.0)        代码: 父类: package jizuiku; class Person { void showDefault() { System.out.println("showDefault"); } private void showPrivate() { System.out.println("sh

C#基础-事件 继承类无法直接引发基类的事件

An event can be raised only from the declaration space in which it is declared. Therefore, a class cannot raise events from any other class, even one from which it is derived. 事件只能在它被声明的声明空间(类)中使用.所以不能从任何其他类引发,即使该类是事件所在类的继承类. 那我们如何才可以引发基类中的事件,给个实例大家一

4.2.1 Codec基类

在codecs模块里定义了与codec对象进行交互的接口,也可以使用它作为其它编解码的基类. 在Python里要求codec对象需要有四个接口:无状态的encoder,无状态的decoder,StreamReader和StreamWriter.而StreamReader和StreamWriter通常是由无状态的encoder/decoder通过文件协议来实现.同时codec对象还需要处理在编码和解码里出现的错误. 4.2.1.1 错误处理 codecs模块通过errors字符串参数来实现不同的错