Вы находитесь на странице: 1из 1

System.out.println(foundIt ?

"Found it" : "Didn't find it"); //if foundIt = true then print Found it else Didnt find it Return - to end a method or return a value in a function Subclasses inherit all the fields and methods of its superclass Super.* to refer to superclass Use final to indicate that a method cannot be overwritten
Note: If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass.

Methods Modifier Return type Method name Parameters Method body Many methods use void to signify that no value is returned Public int getVolume() { //body here } Constants are declared with final and should be used with static Interfaces - Implements after extends - An interface defines a protocol of communication between two objects. - An interface declaration contains signatures, but no implementations, for a set of methods, and might also contain constant definitions. - A class that implements an interface must implement all the methods declared in the interface. - An interface name can be used anywhere a type can be used. Casting Object obj = new MountainBike(); then obj is both an Object and a Mountainbike (until such time as obj is assigned another object that is not a Mountainbike). This is called implicit casting. If, on the other hand, we write MountainBike myBike = obj; we would get a compile-time error because obj is not known to the compiler to be a MountainBike. However, we can tell the compiler that we promise to assign a MountainBike to obj by explicit casting: MountainBike myBike = (MountainBike)obj;
if (obj instanceof MountainBike) { MountainBike myBike = (MountainBike)obj; }

To check if obj is an MountainBike

Вам также может понравиться