Chapter 22: Classes and Objects
Chapter 22: Classes and Objects
128
Section 21.6: Obtain class that satisfies generic parameter at runtime .............................................................. 128
Section 21.7: Benefits of Generic class and interface ............................................................................................ 129
Section 21.8: Instantiating a generic type ............................................................................................................... 130
Section 21.9: Creating a Bounded Generic Class ................................................................................................... 130
Section 21.10: Referring to the declared generic type within its own declaration .............................................. 132
Section 21.11: Binding generic parameter to more than 1 type ............................................................................. 133
Section 21.12: Using Generics to auto-cast ............................................................................................................. 134
Section 21.13: Use of instanceof with Generics ....................................................................................................... 134
Section 21.14: Dierent ways for implementing a Generic Interface (or extending a Generic Class) .............. 136
Chapter 22: Classes and Objects ...................................................................................................................... 138
Section 22.1: Overloading Methods ......................................................................................................................... 138
Section 22.2: Explaining what is method overloading and overriding ................................................................ 139
Section 22.3: Constructors ........................................................................................................................................ 141
Section 22.4: Initializing static final fields using a static initializer ........................................................................ 142
Section 22.5: Basic Object Construction and Use .................................................................................................. 143
Section 22.6: Simplest Possible Class ...................................................................................................................... 145
Section 22.7: Object Member vs Static Member .................................................................................................... 145
Chapter 23: Local Inner Class ............................................................................................................................. 147
Section 23.1: Local Inner Class ................................................................................................................................. 147
Chapter 24: Nested and Inner Classes .......................................................................................................... 148
Section 24.1: A Simple Stack Using a Nested Class ............................................................................................... 148
Section 24.2: Static vs Non Static Nested Classes ................................................................................................. 148
Section 24.3: Access Modifiers for Inner Classes ................................................................................................... 150
Section 24.4: Anonymous Inner Classes ................................................................................................................. 151
Section 24.5: Create instance of non-static inner class from outside ................................................................. 152
Section 24.6: Method Local Inner Classes .............................................................................................................. 153
Section 24.7: Accessing the outer class from a non-static inner class ................................................................ 153
Chapter 25: The java.util.Objects Class ......................................................................................................... 155
Section 25.1: Basic use for object null check .......................................................................................................... 155
Section 25.2: Objects.nonNull() method reference use in stream api ................................................................. 155
Chapter 26: Default Methods ............................................................................................................................. 156
Section 26.1: Basic usage of default methods ........................................................................................................ 156
Section 26.2: Accessing overridden default methods from implementing class ............................................... 156
Section 26.3: Why use Default Methods? ............................................................................................................... 157
Section 26.4: Accessing other interface methods within default method ........................................................... 157
Section 26.5: Default method multiple inheritance collision ................................................................................. 158
Section 26.6: Class, Abstract class and Interface method precedence .............................................................. 159
Chapter 27: Packages ............................................................................................................................................ 161
Section 27.1: Using Packages to create classes with the same name ................................................................. 161
Section 27.2: Using Package Protected Scope ...................................................................................................... 161
Chapter 28: Inheritance ......................................................................................................................................... 163
Section 28.1: Inheritance ........................................................................................................................................... 163
Section 28.2: Abstract Classes ................................................................................................................................. 164
Section 28.3: Using 'final' to restrict inheritance and overriding .......................................................................... 166
Section 28.4: The Liskov Substitution Principle ...................................................................................................... 167
Section 28.5: Abstract class and Interface usage: "Is-a" relation vs "Has-a" capability ................................... 167
Section 28.6: Static Inheritance ................................................................................................................................ 171
Section 28.7: Programming to an interface ........................................................................................................... 172