Lecture 7B Flashcards
When is type compatibility checked?
At compile time, before runtime. Java is statically typed. This check is called type checking.
When is a variable polymorphic?
When it can store references of objects with several different types.
Shape s = new Circle(); name the types
The static type of s is reference type Shape, the dynamic type of s is reference type Circle. Java determines dynamic type at runtime.
When does dynamic dispatch work?
Only for overriding methods. Ie Shape s = new Circle(); s.circleMethod() doesn’t work.
Interfaces - rules:
Only visibility modifier allowed is public, only has abstract methods, only has none or static final fields,
What i relationship between class an interface?
A weak is-a relationship.
How to derive an interce from another interface?
Interface1 extends interface2, interface3 {}
When to use an interface?
To achieve a restricted form of multi-inheritance, to separate public aspects of a class from implementation (an interface is all you need to interact with a class), to demand functionality from several different classes.
What are primitive wrapper classes?
Integer, Double etc Conversion between primitives and wrappers done automatically by boxing and unboxing.