/*
* [javaModifiers] class className [extends someSuperClass]
* [implements someInterfaces sep by commas]
* {
* // Data members
* // Constructors
* // Methods
* }
*/
public class Candidate { // ... }
class Stats extends ToolSet { // ... }
public class Report extends ToolSet implements Runnable { // ... }
/*
* [javaModifier] type dataMemberName;
* [javaModifiers] type methodName (parameterList)
* [throws listOfExceptionsSepByComas] {
* // ...
* }
*
*/
public class Candidate {
private String firstName;
private String lastName;
private int year;
public void setYear(int y) { year = y; }
public String getLastName() { return lastName; }
}
public class VotingMachine {
// ...
public void startUp() { // ... }
public void startUp(int delay) { // ... }
private String startUp(District d) throws new IOException { // ... }
}
public class Display {
void startUp() {
// ...
}
}
public class TouchScreenDisplay extends Display {
void startUp() {
// ...
}
}
public class Candidate {
Candidate(int id) {
this.identification = id;
}
Candidate(int id, int age) {
this.identification = id;
this.age = age;
}
}
public class Machine {
boolean state;
void setState(boolean s) { state = s; }
boolean getState() { return state; }
}
public class VotingMachine extends Machine { // ... }
public class Curtain {
public Curtain(int length, int width) { // ... }
public Curtain() { this(10,9); }
}
public void setColor(String color) {
this.color = color;
}
public abstract class Shape {
public abstract void draw();
}
public class Triangle extends Shape {
public void draw() {
// ...
}
}
public class Voter {
static int count = 0;
// static constants
static final int AGE_IMIT;
static {
// init static members
AGE_IMIT = 18;
}
public Voter() { counter++; }
public static int getVoterCount() {
return count;
}
}
public interface Reportable {
void genReport(String repType);
void printReport(String repType);
}
public abstract class A implements Reportable {
// ...
}
public abstract class Shape {
public abstract void draw();
}
public class Triangle extends Shape { // ... }
public class Rectangle extends Shape { // ... }
public class Circle extends Shape { // ... }
public class Main {
public static void main(String[] args){
ArrayList<Shape> myShapes = new ArrayList<Shape>();
myShapes.add(new Circle());
myShapes.add(new Triangle());
myShapes.add(new Rectangle());
for(int ii = 0; ii < myShapes.size(); ii++) {
myShapes.get(ii).draw();
}
}
}
enum DisplayButton {
ROUND (.50f),
SQUARE (.40f);
private final float size;
DisplayButton(float size) { this.size = size; }
private float size() { return size; }
}
DisplayButton round = DisplayButton.ROUND;
// @Override is a marker annotation
// compile warning will be returned if method cannot be found
@Override public String toString() { // ... }
// @interface annotationName { ... } // defines annotation
public @interface Feedback {
String reportName();
String comment default "None";
}
@Feedbaack(reportName="Report 1")
public void myMethod() { // ... }
Handbuch der Java-Programmierung
(5. Auflage)
Thank you for your attention!