From 928e53a10885f4bfcb6b603072b0a27cc0caf36d Mon Sep 17 00:00:00 2001 From: "U-Christopher-PC\\Christopher" Date: Mon, 10 Feb 2014 14:28:54 -0700 Subject: Added section on interfaces. Added array info --- java.html.markdown | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 1fbf6a21..3cab973e 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -101,14 +101,17 @@ public class LearnJava { // Arrays //The array size must be decided upon instantiation - //The format for declaring an array is follows: + //The following formats work for declaring an arrow // [] = new []; + // [] = new []; int [] intArray = new int[10]; String [] stringArray = new String[1]; - boolean [] booleanArray = new boolean[100]; + boolean boolArray [] = new boolean[100]; // Another way to declare & initialize an array int [] y = {9000, 1000, 1337}; + String names [] = {"Bob", "John", "Fred", "Juan Pedro"}; + boolean bools[] = new boolean[] {true, false, false}; // Indexing an array - Accessing an element System.out.println("intArray @ 0: " + intArray[0]); @@ -405,6 +408,46 @@ class PennyFarthing extends Bicycle { } +//Interfaces +//Interface declaration syntax +// interface extends { +// //Constants +// //Method declarations +//} + +//Example - Food: +public interface Edible { + public void eat(); //Any class that implements this interface, must implement this method +} + +public interface Digestible { + public void digest(); +} + + +//We can now create a class that implements both of these interfaces +public class Fruit implements Edible, Digestible { + public void eat() { + //... + } + + public void digest() { + //... + } +} + +//In java, you can extend only one class, but you can implement many interfaces. +//For example: +public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo { + public void InterfaceOneMethod() { + + } + + public void InterfaceTwoMethod() { + + } +} + ``` ## Further Reading -- cgit v1.2.3