Java Cheat Sheet
Java Cheat Sheet
public BasicClass() {
// This is the constructor.
}
/**
* Inheritance. Use "extends".
*/
public class Bicycle {
interface Animal {
public void eat();
public void travel();
}
/**
* Abstract classes in Java are pretty classic.
* They can contain empty and filled methods.
* They provide partially-built functionality
* on which other classes can be built.
* Consider these when you want to share code
* among several closely-related classes.
*/
/**
* Inner Classes are those that are defined entirely
* within another class. They are usually helper
* classes and never have their own *.java file.
*/
/**
* Anonymous classes allow you to implement a one-off class.
* Hopefully simple, this class won't need to be re-used later.
* The anonymous class is a subclass of something else.
*/
class ProgrammerInterview {
public void read() {
System.out.println("Programmer Interview!");
}
}
class Website {
# This creates an anonymous inner class
ProgrammerInterview pInstance = new ProgrammerInterview() {
public void read() {
System.out.println("anonymous ProgrammerInterview");
}
};
}