difference between Interface and abstract class in Java
来源:互联网 发布:少年包青天1抄袭 知乎 编辑:程序博客网 时间:2024/06/05 03:57
- one class can ony extends one super class, but can implements multiple interfaces
- abstract class can have codes:
- class/instance field proper value initilizers
- instance initilizers
- class initilizers
- interface can have only codes:
- class field proper value initilizers
- Superclasses need to be initialized before subclasses, so these classes are likely already loaded. Superinterfaces do not need to be initialized when a class that implements them is initialized. However, superinterfaces must be loaded when the class that implements them (or the interface that extends them) is loaded. (They won't be initialized, just loaded and possibly linked at the option of the virtual machine implementation.) All a class's supertypes will be loaded when the class is loaded.
- Interfaces may also be awarded a
method in the class file. All fields declared in an interface are implicitly public, static, and final and must be initialized with a field initializer. If an interface has any field initializers that don't resolve at compile-time to a constant, that interface will have a()
method. But we cannot have an explicit class initilizer block for it(cinit)
The Java compiler generates at least one instance initialization method for every class it compiles. In the Java class file, the instance initialization method is named "<init>
." For each constructor in the source code of a class, the Java compiler generates one <init>()
method. If the class declares no constructors explicitly, the compiler generates a default no-arg constructor that just invokes the superclass's no-arg constructor. As with any other constructor, the compiler creates an <init>()
method in the class file that corresponds to this default constructor.
In Java programs, classes can be instantiated explicitly or implicitly. The four ways a class can be instantiated explicitly are
- with the
new
operator, - by invoking
newInstance()
on aClass
orjava.lang.reflect.Constructor
object, - by invoking
clone()
on any existing object, - or by deserializing an object via the
getObject()
method of classjava.io.ObjectInputStream
.
new operator and newInstance() will call respondent init() methods, other ways will not.
http://www.artima.com/insidejvm/ed2/lifetypeP.html- difference between Interface and abstract class in Java
- difference between Abstract class and interface in java
- difference between Abstract class and interface in java
- Difference between Abstract Class and Interface in Java
- Java - Difference between Abstract class and Interface
- Difference between Abstract class and interface
- difference between abstract class and interface
- What's the difference between Interface and an abstract class in visual c#?
- What is difference between abstract class and interface
- interface and abstract class in java
- [java] difference between Abstract Classes of Interface
- Java: abstract and interface difference
- Differences between abstract class and interface
- Difference Between Class.ForName() And ClassLoader.LoadClass() Methods In Java
- java interface and abstract class
- Java-Abstract Class and Interface
- Programming in Java: Multi-threads and interface vs abstract class
- Different Between An Interface and An Abstract Class
- 关于Ext4的mvc模式构建前端界面的问题!reader.read is not a function
- 今天和大家讲一下怎么样简单的把壁纸作为背景,在中间加一个textview效果图如下
- 今天开始阅读《现代操作系统》
- Java中的instanceof关键字
- 排序算法小结
- difference between Interface and abstract class in Java
- jquery 弹出一个淡出窗口示例代码
- MYSQl left join 联合查询效率分析
- usb Mass Storage
- PostgreSQL用户创建删除及error while loading shared libraries解决方法
- 大型网站架构系列之一,不得不考虑的问题
- Spring6:Spring中的事务管理
- 开源网吧管理系统 网吧防逃费 进销存 考勤管理
- const与*