diff options
author | Vojta Svoboda <vojtasvoboda.cz@gmail.com> | 2015-10-08 22:15:32 +0200 |
---|---|---|
committer | Vojta Svoboda <vojtasvoboda.cz@gmail.com> | 2015-10-08 22:15:32 +0200 |
commit | 838701b917bb914f3483b6e9233920a752d20f82 (patch) | |
tree | a430654109b2f8e6a47eddf057f86d73630314a7 /java.html.markdown | |
parent | 4d619e9b0fc4a061fa720b47b22068c8661e9be6 (diff) | |
parent | abd7444f9e5343f597b561a69297122142881fc8 (diff) |
Merge branch 'master' into translation/json-cs
Diffstat (limited to 'java.html.markdown')
-rw-r--r-- | java.html.markdown | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/java.html.markdown b/java.html.markdown index 478ec683..fc7948d6 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -47,9 +47,9 @@ public class LearnJava { /////////////////////////////////////// - // Variables + // Variables /////////////////////////////////////// - + /* * Variable Declaration */ @@ -325,29 +325,29 @@ public class LearnJava { // toString returns this Object's string representation. System.out.println("trek info: " + trek.toString()); - + // Double Brace Initialization // The Java Language has no syntax for how to create static Collections // in an easy way. Usually you end up in the following way: - + private static final Set<String> COUNTRIES = new HashSet<String>(); static { validCodes.add("DENMARK"); validCodes.add("SWEDEN"); validCodes.add("FINLAND"); } - + // But there's a nifty way to achive the same thing in an // easier way, by using something that is called Double Brace // Initialization. - + private static final Set<String> COUNTRIES = HashSet<String>() {{ add("DENMARK"); add("SWEDEN"); - add("FINLAND"); + add("FINLAND"); }} - - // The first brace is creating an new AnonymousInnerClass and the + + // The first brace is creating an new AnonymousInnerClass and the // second one declares and instance initializer block. This block // is called with the anonymous inner class is created. // This does not only work for Collections, it works for all @@ -500,7 +500,7 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, } -// Abstract Classes +// Abstract Classes // Abstract Class declaration syntax // <access-level> abstract <abstract-class-name> extends <super-abstract-classes> { // // Constants and variables @@ -512,26 +512,26 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne, // Also abstract classes CAN have the "main" method. // Abstract classes solve these problems. -public abstract class Animal +public abstract class Animal { public abstract void makeSound(); // Method can have a body public void eat() { - System.out.println("I am an animal and I am Eating."); + System.out.println("I am an animal and I am Eating."); // Note: We can access private variable here. age = 30; } - // No need to initialize, however in an interface + // No need to initialize, however in an interface // a variable is implicitly final and hence has // to be initialized. private int age; public void printAge() { - System.out.println(age); + System.out.println(age); } // Abstract classes can have main function. @@ -552,7 +552,7 @@ class Dog extends Animal // age = 30; ==> ERROR! age is private to Animal } - // NOTE: You will get an error if you used the + // NOTE: You will get an error if you used the // @Override annotation here, since java doesn't allow // overriding of static methods. // What is happening here is called METHOD HIDING. |