Learn Java for Web Development

(Tina Meador) #1

390 APPENDIX A: Introduction to Java


Listing A-15 illustrates how Figure A-1 could be implemented in code. It illustrates implementation
inheritance using the keyword extends in line 26.


Listing A-15. Implementation Inheritance



  1. package apress.appendix_A



  2. public class ClassA {



  3. // Instance methods

  4. public void method1() {

  5. System.out.println(" classA - method1");



  6. }



  7. private void method2() {

  8. System.out.println(" classA - method2");



  9. }



  10. // Static methods

  11. public static void method3() {

  12. System.out.println(" classA - method3");



  13. }



  14. }


Figure A-1. Parent-child relationship. ClassB extends ClassA

Free download pdf