栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java学习之final关键字

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java学习之final关键字

复盘:

final关键字正如其名字一样,最终的,可以修饰变量(属性和局部变量),方法,代码块、类。

对于final修饰的类,表示该类不可以再被其他类继承,已经到了最后一代。

final修饰方法:表示方法不可以被重写

final修饰变量:表示是一个常量,通常定义全局变量时与static连用,static final

笔记:

package oop.keywords;

public class FinalTest {

	final int WIDTH=10;//显式初始化
	final int LEFT;
	final int RIGHT;
	final int DOWN;
	{
		LEFT=1;	
	}
	public FinalTest()
	{
		RIGHT=2;
		this.DOWN = 0;
	}
	public FinalTest(int n)
	{
		RIGHT=n;
		this.DOWN = 0;
		
	}
	public void doWidth()
	{
//		width=11;The final field FinalTest.width cannot be assigned
	}
	
	public void show()
	{
		final int NUM=10;//final修饰方法体里面的局部变量
		
	}
	public void show(final int num)
	{
//		num=20;
	}
}

final class Final{
	
}
//class B extends Final{
//	
//} the type B cannot subclass the final class Final

//class A extends String{
//	
//}
class AA{
	 public final void show()
	{
		
	}
}
class BB extends AA
{
//	private void show() {
//		// TODO Auto-generated method stub
//
//	} Multiple markers at this line
//	- Cannot override the final method from AA
}



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/683461.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号