class Car extends Vehicle{ public Car(String n) { super (n); } } class Vehicle { protected String name; public Vehicle(String n) { name = n; } } Case 1
Method Overriding § A child class can override (redefine) the definition of an inherited method. (The new method must have the same signature.) § A method with the final modifier cannot be overridden. Warning: § Applied to variables final modifier makes them constant.
Method Overloading public int calculate (int num1, int num2) { int sum = num1 + num2; return sum; } public int calculate (int num1, int num2, int num3) { int sum = num1 + num2 + num3; return sum; } 17
Abstract Classes § cannot be instantiated and contains one or more abstract methods (no definition body). § can contain methods § can contain data declarations
Abstract Methods § An abstract method is a method without a body. § It cannot be final or static because there is no definition, and it should be changed later.
Ph.D. [email protected] Fall 2021 Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University. They cannot be distributed or used for another purpose.