Index


Casting


Generally typecasting is not needed because Java's generics allows for dynamic types. However there are occassions where it is helpful.

What we are doing in this example is casting type "Object" to type "City". This is called typecasting.

typecasting means that we override the given general type with a more specific type. Note that in this example we first verify that the actual object is a "City" object. Then we can safely typecast.
public boolean equals(Object o)  {
	if (o == this)
		return true;
	if (!(o instanceof City))
		return false;
	City other = (City)o;
	return
		safeEquals(this.getName(), other.getName())
			&& safeEquals(this.getStateAbbrev(), other.getStateAbbrev())
			&& safeEquals(this.getZip(), other.getZip());
}

Exceptions


TypeDescription
Uncaught ExceptionsExceptions that do not need "throws" on the method header and do not need to be caught be method senders.
Caught ExceptionsExceptions that yes do need "throws" on the method header and yes do need to be caught be method senders.


From oracle.com:


References:

Class Access Modifiers


Also referred to as class visibility.

These modifiers control which other classes can access the given class.

Class Access Levels
ModifierVisibility
no modifierpackage
publicuniversal


Method Access Modifiers


Also referred to as method access level

Method Access Levels
ModifierClassPackageSubclassWorld
publicYYYY
protectedYYYN
no modifierYYNN
privateYNNN

This table is from Oracle...