Packages & Binding CompSci 230 S2 2015 Software Design and Construction.

Slides:



Advertisements
Similar presentations
Lecture 5: Interfaces.
Advertisements

Java Implementation, Part 2S CompSci 230 Software Construction.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
Java Implementation: Part 2 Version 1.4 of : rearranged slides CompSci 230 Software Construction.
Inheritance Inheritance Reserved word protected Reserved word super
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Inheritance and Polymorphism.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
Java Programming Chapter 3 More about classes. Why?  To make classes easier to find and to use  to avoid naming conflicts  to control access  programmers.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Inheritance and Polymorphism. 2 Motivations Suppose you will define classes to model circles, rectangles, and triangles. These classes have many common.
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Java Implementation: Part 3 Software Construction Lecture 8.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 11 Inheritance and Polymorphism.
Inheritance and Polymorphism Daniel Liang, Introduction to Java Programming.
Inheritance in the Java programming language J. W. Rider.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Data Structures Using Java1 Chapter 2 Inheritance and Exception Handling.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Inheritance and Access Control CS 162 (Summer 2009)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Lecture 4: Extending Classes. Concept Inheritance: you can create new classes that are built on existing classes. Through the way of inheritance, you.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
1 Object-Oriented Programming Inheritance. 2 Superclasses and Subclasses Superclasses and Subclasses  Superclasses and subclasses Object of one class.
Inheritance ndex.html ndex.htmland “Java.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
CompSci 230 S Programming Techniques
Modern Programming Tools And Techniques-I
Software Construction
Chapter 11 Inheritance and Polymorphism
CompSci 230 S Programming Techniques
Inheritance and Polymorphism
Overloading and Constructors
Chapter 9 Inheritance and Polymorphism
Extending Classes.
Java Programming Language
Packages and Interfaces
Inheritance in Java CS 3331 Fall 2009.
Chapter 11 Inheritance and Polymorphism Part 2
Chapter 11 Inheritance and Encapsulation and Polymorphism
Overloading Each method has a signature: its name together with the number and types of its parameters Methods Signatures String toString()
Presentation transcript:

Packages & Binding CompSci 230 S Software Design and Construction

Agenda & Reading  Topics:  Packages  Access Modifiers  Static & Dynamic Binding  Casting  Reading  The Java Tutorial  Creating and Using PackagesPackages  Controlling Access to Members of a ClassAccess  Overriding and Hiding Methods Overriding  Hiding Fields Hiding Fields 062

Packages  Definition: A package is a grouping of related types providing access protection and name space management.  A package is a namespace that organizes a set of related classes and interfaces.”  Purpose: “To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages.”  Conceptually you can think of packages as being similar to different folders on your computer.  Note that types refers to classes, interfaces …  Examples:  java.io — file operations  java.lang — basic language functionality and fundamental types  java.util — collection data structure classes  java.awt — basic hierarchy of packages for native GUI components 063

Creating a Package  “To create a package, you  choose a name for the package (folder) and  put a package statement with that name at the top of every source file that contains the types that you want to include in the package.  Rules:  There can be only one package statement in each source file, and must be the first line in the source file.  If you put multiple types in a single source file, only one can be public, and it must have the same name as the source file.  You can include non-public types in the same file as a public type This rule makes it easy for the class loader, and the human programmer, to find the definition for a public type. package X; 064

One public type per file!  “If you put multiple types in a single source file, only one can be public, and it must have the same name as the source file.  For example, you can  define public class Circle in the file Circle.java,  define public interface Draggable in the file Draggable.java,  define public enum Day in the file Day.java, and so forth.  “You can include non-public types in the same file as a public type  (this is strongly discouraged, unless the non-public types are small and closely related to the public type),  but only the public type will be accessible from outside of the package.  All the top-level, non-public types will be package private.”  This rule makes it easy for the class loader, and the human programmer, to find the definition for a public type.  The name of a package determines the directory in which the files of this package should be stored.  The name of a public type determines the name of the file in which the type’s definition must be found.” 065

The default package  “If you do not use a package statement, your type ends up in an unnamed package.  Generally speaking, an unnamed package is only for small or temporary applications or when you are just beginning the development process.  Otherwise, classes and interfaces belong in named packages.” 066

Package naming conflicts  “With programmers worldwide writing classes and interfaces using the Java programming language,  it is likely that many programmers will use the same name for different types.  The compiler allows both classes to have the same name if they are in different packages.  The fully qualified name of each Rectangle class includes the package name.  That is, the fully qualified name of the Rectangle class in the graphics package is graphics.Rectangle, and  the fully qualified name of the Rectangle class in the j ava.awt package is java.awt.Recta ngle. 067

External references  To use a public package member from outside its package, you must do one of the following:  The fully qualified name for class C in package p is p.C  To import class C from package p, you write import p.C  To import an entire package p, you write import p.* package p1; public class Protection { int n_default = 1; public int n_public = 2; protected int n_protected = 3; private int n_private = 4; } public class Class1 { public static void main(String[] args) { p1.Protection c = new p1.Protection(); } 068

Access Modifiers  Classes, and their fields and methods have access levels to specify how they can be used by other objects during execution  A private field or method is accessible only to the class in which it is defined.  A protected field or method is accessible to the class itself, its subclasses, and classes in the same package.  A public field or method is accessible to any class of any parentage in any package PrivateProtectedPublicDefault Class itselfYES Other Subclasses within a packageNoYES Other classes within a packageNoYES Other subclasses outside this packageNoYES No Other classes outside this packageNo YESNo 069

Example: subclasses within a package package p1; public class Protection { int n_default = 1; public int n_public = 2; protected int n_protected = 3; private int n_private = 4; } package p1; public class Derived extends Protection { public static void main(String[] args) { Derived b = new Derived(); System.out.println("n_default=" + b.n_default); System.out.println("n_public=" + b.n_public); System.out.println("n_protected=" + b.n_protected); // System.out.println("n_private" + b.n_private); } C:/06/access> javac p1/*.java java p1.Derived Within a package n_default=1 n_public=2 n_protected=3 Example: p1/Derived.java No access to Private variable Protection Derived SamePackage P2Derived OtherPackage p1 p2 0610

Example: Other classes within a package package p1; public class Protection { int n_default = 1; public int n_public = 2; protected int n_protected = 3; private int n_private = 4; } package p1; public class SamePackage { public static void main(String[] args) { Protection b = new Protection(); System.out.println("n_default=" + b.n_default); System.out.println("n_public=" + b.n_public); System.out.println("n_protected=" + b.n_protected); // System.out.println("n_private" + b.n_private); } C:/06/access> javac p1/*.java java p1.SamePackage With a package n_default=1 n_public=2 n_protected=3 Protection Derived SamePackage P2Derived OtherPackage Example: p1/SamePackage.java No access to Private variable p1 p2 0611

Example: subclasses outside this package package p1; public class Protection { int n_default = 1; public int n_public = 2; protected int n_protected = 3; private int n_private = 4; } package p2; public class P2Derived extends p1.Protection { public static void main(String[] args) { P2Derived b = new P2Derived(); //System.out.println("n_default=" + b.n_default); System.out.println("n_public=" + b.n_public); System.out.println("n_protected" + b.n_protected); //System.out.println("n_private" + b.n_private); } C:/06/access> javac p1/*.java javac p2/*.java java p2.P2Derived Different packages n_public=2 n_protected=3 Protection Derived SamePackage P2Derived OtherPackage Example: p2/P2Derived.java No access to Private variable No access to the default variable p1 p2 0612

Example: Other classes outside this package package p1; public class Protection { int n_default = 1; public int n_public = 2; protected int n_protected = 3; private int n_private = 4; } package p2; public class OtherPackage { public static void main(String[] args) { p1.Protection b = new p1.Protection(); // System.out.println("n_default=" + b.n_default); System.out.println("n_public=" + b.n_public); // System.out.println("n_protected" + b.n_protected); // System.out.println("n_private" + b.n_private); } C:/06/access> javac p1/*.java javac p2/*.java java p2.OtherPackage Different packages n_public=2 Protection Derived SamePackage P2Derived OtherPackage Example: p2/OtherPackage.java No access to - Default - protected - private p1 p2 0613

Statically or Dynamically typed  Programming languages generally offer some sort of type system, and can be described as being either statically typed or dynamically typed  With a statically typed language, compile-time checks are carried out to determine whether variable usage is valid  In a dynamically typed language, variables are not associated with a type and are simply names that can be assigned arbitrary values Java int x = 10; x = "Hello"; Python x = 10; x = "Hello"; 0614

Java - statically typed language  Every variable name is bound both  to a static type (static type at compile time, by means of a data declaration) and  to an object (dynamic type) or null  The binding to an object is optional.  The type imposes restrictions on how a variable can be used. The type restricts:  the classes of object to which the variable can refer  the message that can be sent using the variable  Restrictions are checked at compile-time  The compiler will not issue code if it detects a violation.  Java is a “type-safe” language: its compile-time checking restricts the amount of damage that can be done by careless or malicious programmers. Ball b1 = new Ball(...); Ball b2 = null; static type dynamic type 0615

Static Typing Restrictions  A reference variable of static type T can refer to an instance of class T or to an instance of any of T’s subclasses  In other words, an instance of class T can always be substituted for an instance of any subclass of T  Through a reference variable of static type T, the set of messages that can be sent using that variable are the methods defined by class T and its superclasses  A variable’s static type is fixed at compile time but its dynamic type may vary at run-time. 0616

Static Binding: Instance Variables  Note:  Access to fields is governed by the form of the reference class Base { public int x = 10; } public class Derived extends Base { public int y = 20; } //Case 1: Base b1 = new Base(); System.out.println("b1.x=" + b1.x); Example: instance_var/Derived.java Base b1-> x=10 Derived b2-> x=10 y=20 //Case 2: Derived b2 = new Derived(); System.out.println("b2.x=" + b2.x); System.out.println("b2.y=" + b2.y); //Case 3: Base b3 = new Derived(); System.out.println("b3.x=" + b3.x); //System.out.println("b3.y=" + b3.y); Base b3-> x=10 y=20 instance variable x in Base instance variable x : inherited from Base instance variable y in Derived From superclass instance variable x : inherited from Base, There is no y declared in Base class -> compile error! b3 is declared as type Base, static type = base; dynamic type = Derived 0617

Static Binding – Hiding a Field  Within a class, a field that has the same name as a field in the superclass hides the superclass's field class Base2 { public int x = 10; } public class Derived2 extends Base2 { public int x = 20; } Example: shadow/Derived.java Derived b2-> x=10 x=20 //Case 2: Derived2 b2 = new Derived2(); System.out.println("b2.x=" + b2.x); //Case 3: Base2 b3 = new Derived2(); System.out.println("b3.x=" + b3.x); Base b3-> x=10 x=20 Base b1-> x=10 //Case 1: Base2 b1 = new Base2(); System.out.println("b1.x=" + b1.x); Note: Access to fields is governed by the form of the reference instance variable x in Base instance variable x from Derived (20) instance variable x from Base, (10) b3 is declared as type Base 0618

Get the hiding values  Within the subclass, the field in the superclass cannot be referenced by its simple name  To "unshadow" it by referring to super.x  Note:  this.x access the field name x, defined in the child class  super.x access the field name x, defined in a parent class  super.super.x is not valid  x was not specified as private. public class Derived extends Base {... public void method1() { System.out.println("x from Derived:" + x); System.out.println("x from superclass: " + super.x);... method In the subclass 0619

Static Binding - Static Variables class Base { public static int x; public Base() { x++; } public class Derived extends Base { public static int y; public Derived() { y++; } //Case 1 Base b1 = new Base(); System.out.println("Base.x=" + Base.x); System.out.println("Derived.y=" + Derived.y); //Case 2 Derived b2 = new Derived(); System.out.println("Base.x=" + Base.x); System.out.println("Derived.x=" + Derived.x); System.out.println("Derived.y=" + Derived.y); Base: x= 0->1 Derived: y= 0 b1 Example: static_var/Derived.java Note: Access to fields is governed by the form of the reference One copy only, all instances of the class share the same static variable Class variable can be accessed before an object of a class is created, and without reference to a particular object class variables: one copy only 1010 Base: x= 0->1->2 Derived: y= 0 ->1 b1 b //case 3 Base b3 = new Derived(); System.out.println("Derived.x=" + Derived.x); System.out.println("Derived.y=" + Derived.y); class variable x : inherited from Base Derived: y= 0 ->1->2 b1 b Base: x= 0->1->2->3 b3 0620

Static Methods class Base { public static int x=1; public static int getX() { return x; } public class Derived extends Base { public static int y=2; public static int getY() { return y; } public static int getX() { return 10; } Example: static_method/Derived.java Base b1 = new Base(); Base b2 = new Derived(); System.out.println("b1.getX()=" + b1.getX()); System.out.println("b2.getX()=" + b2.getX()); //System.out.println("b2.getY()=" + b2.getY()); 1111 Invoke getX in Base No Overriding for static method Compile error No getY in Base System.out.println("Derived.x=" + Derived.getX()); System.out.println("Derived.y=" + Derived.getY()); 10 2 Invoke getX and getY in Derived Note: Static methods can only invoke other static methods and access other static variables Only the non-static methods of a class can be overridden 0621

Dynamic Binding  Dynamic Binding refers to the case where compiler is not able to resolve the call and the binding is done at runtime only.  A call of that method (method1) can only be resolved at runtime as the compiler can't be sure of what type of object this reference would be pointing to at runtime.  The search for a method begins with the dynamic class.  If this class doesn’t implement the method (i.e. it doesn’t introduce or override the method), the search progresses to it’s superclass. This process is repeated up the hierarchy until the method is found. Derived b2 = new Derived(); Base b3 = new Derived(); b2.f(); class Base { public void f() {... } public void g{} {... } } public class Derived extends Base { public void g{} {... } public void h() {... } } Dynamic class b2.g(); b3.f(); b3.g(); f() in Derived, f() in Base? Invoke f() in Base g() in Derived? Invoke g() in Derived f() in Base? Invoke f() in Base g() in Base? Invoke g() in Derived b2.h(); h() in Derived? Invoke h() in Derived b3.h(); h() in Base? Compile time error 0622

Casting  Casting an object to a different type will permit access to fields shadowed by the type of the original object  Casting an object to a different type will have NO effect on which method is invoked in response to a given message. Once overridden, methods remain overridden  To cast, just precede a value with the parenthesised name of the desired type  A ClassCastException is thrown if the type cast is incompatible with the type of object to be pointed to.  To check that a potential cast is safe, the instanceof operator should be used  The instanceof operator Can be used to determine the type of an object  Returns true if can be assigned into a reference of type. That is, instanceof checks if the is-an instance of the specified class, provided obj is not null. Derived d = (Derived) b3; Base b4 = (Base) b4; instanceof 0623

Primitive Types  Widening conversions  Wider assignment  Wider Casting  Casting a value to a wider value is always permitted but never required. However, explicitly casting can make your code more readable  Narrowing conversion  Narrow assignment – Compile-time error  Narrow Casting – Loss of information  You must use an explicit cast to convert a value in a large type to a smaller type, or else converting that value might result in a loss of precision. double d = 4.9; int i = 10; double d1, d2; d1 = i; d2 = (double) i; Example: casting/Primitive.java Wider type Casting needed Assignment conversion d1 = 10.0 Casting conversion (optional) d2 = 10.0 double d = 4.9; int i = 10; int i1, i2; //i1 = d; i2 = (int) d; Assignment conversion Compile-time error Narrow Casting: i2=4 NOTE: Everything beyond the decimal point will be truncated 0624

Object Types  Widening conversions  Wider object reference assignment conversion  Wider object reference casting (optional)  Note:  Reference conversion, like primitive conversion, takes place at compile time, because the compiler has all the information it needs to determine whether the conversion is legal  Inheritance relation is an “is a” relation; the parent object is more general than child object  The general rule of thumb is that converting to a superclass is permitted (because super class is wider than sub class) Base b = new Base(); Derived d = new Derived(); Base b1, b2; System.out.println(d.y); b1 = d; //System.out.println(b1.y); Example: casting/CastObject.java Base Derived Wider type b2 = (Base) d; //System.out.println(b2.y); Assignment conversion - OK However, no access to fields in Derived Widening Casting conversion - OK However, no access to fields in Derived 0625

Object Types  Narrowing conversion  Narrow object reference assignment – Compile-time error  Narrow object reference casting –  Compile-time OK,  Run-time?  Like primitive casting: By using a cast, you convince the compiler to let you do a conversion that otherwise might not be allowed  The run-time check determines whether the class of the object being cast is compatible with the new type Person Student Wider type Base b = new Base(); Derived d = new Derived(); Derived d1, d2, d3; //d1 = b; d2 = (Derived) b; Compile-time error Compile-time OK, Run-time ERROR b is an instance of class Base, not Derived java.lang.ClassCastException: Base Base b-> x=10 Base d_as_b = new Derived();d3 = (Derived) d_as_b; Compile-time OK, narrow casting, casting from superclass to subclass Run-time OK d_as_b is an instance of Derived Base d_as_b-> x=10 y=20 Example: casting/CastObject.java 0626

Using Casting  Shadowing  Using type casting, it is possible to recover a hidden member (class variable, class method, or an instance variable), but not an overridden method (i.e. an instance method). An overridden method can be recovered only by means of a super call in derived class Derived2 d-> x=10 x=20 Base2 b-> x=10 x=20 Example: Casting/Recover.java Hiding Derived2 d = new Derived2(); Base2 b = new Derived2(); System.out.println( "d.x=" + d.x); System.out.println( "((Base2)d).x=" + ((Base2)d).x); System.out.println( "b.x=" + b.x); System.out.println( "((Derived2)b).x=" + ((Derived2)b).x); Hiding class Base2 { public int x = 10; } public class Derived2 extends Base2 { public int x = 20; } 0627

Instanceof Person Student TertiaryStudentCollegeStudent Employee Person p = new Person(); System.out.println(p instanceof Person); System.out.println(p instanceof Student); true false Person p1 = new Student(); System.out.println(p1 instanceof Person); System.out.println(p1 instanceof Student); System.out.println(p1 instanceof Employee); true false Example: TestInstanceOf.java p Person Student TertiaryStudentCollegeStudent p1 Employee 0628

Instanceof TertiaryStudent ts = new TertiaryStudent(); System.out.println(ts instanceof Student); // System.out.println(ts instanceof CollegeStudent); // System.out.println(ts instanceof Employee); true Student s2 = new TertiaryStudent(); System.out.println(s2 instanceof TertiaryStudent); System.out.println(s2 instanceof CollegeStudent); //System.out.println(s2 instanceof Employee); true false no instance of TertiaryStudent, or any of its possible subclasses could possibly be an instance of any subclass of CollegeStudent/Employee => Compile-time error Person Student TertiaryStudentCollegeStudent ts Employee Person Student TertiaryStudentCollegeStudent s2 Employee 0629

Exercise:  At compile-time, checking is carried out to determine whether the cast-type and the type of the existing reference variable are related through inheritance.  At run time, a check is made to determine whether the object actually pointed to is compatible with the cast-type. Person Student TertiaryStudentCollegeStudent Employee Compile- time Run- time (TertiaryStudent) s1OK (TertiaryStudent) s2OK (TertiaryStudent) e1ERROR (TertiaryStudent) s3OKERROR (TertiaryStudent) s4OKERROR (Students) S2OK Student s1 = new TertiaryStudent(); TertiaryStudent s2 = new TertiaryStudent(); Employee e1 = new Employee(); Student s3 = new CollegeStudent(); Student s4 = new Student(); 0630

Summary  Object Conversion  Make it possible to reference an object in a different way by assigning it to an object reference of a different type.  It is handled automatically by the compiler.  The object is NOT converted or changed in any way. Once instantiated, an object NEVER changes its type (a Cat will always be a Cat). The concept is similar to the "widening conversions" performed on primitive data types.  Casting  It is needed when the compiler doesn't recognize an automatic conversion. The concept is similar to the casting of primitive data types to perform a "narrowing conversion".  Casting does not change the reference or the object being pointed to. It only changes the compiler’s treatment of the reference  Casting is only legal between objects in the same inheritance hierarchy  You can safely cast from an object to its superclass Student s = new Student(); Person p = s; 0631

Overriding, hiding, and overloading methods  “An instance method in a subclass with the same signature (name, plus the number and the type of its parameters) and return type as an instance method in the superclass overrides the superclass's method.”  “If a subclass defines a class method with the same signature as a class method in the superclass, the method in the subclass hides the one in the superclass.  “The distinction between hiding and overriding has important implications.  The version of the overridden method that gets invoked is the one in the subclass.  The version of the hidden method that gets invoked depends on whether it is invoked from the superclass or the subclass.”  “Overloaded methods are differentiated by the number and the type of the arguments passed into the method.”  “The compiler does not consider return type when differentiating methods, so you cannot declare two methods [in the same class] with the same signature even if they have a different return type. 0632