Java
File Class ...................................................................................................................................................... 262
Directories in Java........................................................................................................................................ 272
Listing Directories ........................................................................................................................................ 273
19. Java – Exceptions .................................................................................................................................. 275
Exception Hierarchy..................................................................................................................................... 276
Built-in Exceptions ....................................................................................................................................... 277
Exceptions Methods .................................................................................................................................... 279
Catching Exceptions..................................................................................................................................... 280
Multiple Catch Blocks .................................................................................................................................. 281
Catching Multiple Type of Exceptions ......................................................................................................... 282
The Throws/Throw Keywords ..................................................................................................................... 282
The Finally Block .......................................................................................................................................... 283
The try-with-resources ................................................................................................................................ 285
User-defined Exceptions .............................................................................................................................. 287
Common Exceptions .................................................................................................................................... 290
20. Java – Inner Classes ............................................................................................................................... 291
Nested Classes ............................................................................................................................................. 291
Inner Classes (Non-static Nested Classes) ................................................................................................... 292
Accessing the Private Members .................................................................................................................. 293
Method-local Inner Class ............................................................................................................................. 294
Anonymous Inner Class ............................................................................................................................... 295
Anonymous Inner Class as Argument .......................................................................................................... 296
Static Nested Class....................................................................................................................................... 297
JAVA - OBJECT ORIENTED ........................................................................................................ 299
21. Java – Inheritance ................................................................................................................................. 300
extends Keyword ......................................................................................................................................... 300
Sample Code ................................................................................................................................................ 300
The super keyword ...................................................................................................................................... 302
Invoking Superclass Constructor ................................................................................................................. 305
IS-A Relationship .......................................................................................................................................... 306
The instanceof Keyword .............................................................................................................................. 308
HAS-A relationship....................................................................................................................................... 309
Types of Inheritance .................................................................................................................................... 309
22. Java – Overriding .................................................................................................................................. 311
Rules for Method Overriding ....................................................................................................................... 313
Using the super Keyword ............................................................................................................................ 314
23. Java – Polymorphism ............................................................................................................................ 315
Virtual Methods ........................................................................................................................................... 316
24. Java – Abstraction ................................................................................................................................. 320
Abstract Class .............................................................................................................................................. 320
Inheriting the Abstract Class........................................................................................................................ 323
Abstract Methods ........................................................................................................................................ 324
vii