mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 07:12:31 +03:00
[java/en] Fixed Whitespace
Converted tabs to 4 spaces for consistency.
This commit is contained in:
parent
420e04a590
commit
cea7db46eb
@ -343,9 +343,9 @@ public class LearnJava {
|
|||||||
|
|
||||||
private static final Set<String> COUNTRIES = new HashSet<String>();
|
private static final Set<String> COUNTRIES = new HashSet<String>();
|
||||||
static {
|
static {
|
||||||
validCodes.add("DENMARK");
|
validCodes.add("DENMARK");
|
||||||
validCodes.add("SWEDEN");
|
validCodes.add("SWEDEN");
|
||||||
validCodes.add("FINLAND");
|
validCodes.add("FINLAND");
|
||||||
}
|
}
|
||||||
|
|
||||||
// But there's a nifty way to achive the same thing in an
|
// But there's a nifty way to achive the same thing in an
|
||||||
@ -505,12 +505,12 @@ public class Fruit implements Edible, Digestible {
|
|||||||
public class ExampleClass extends ExampleClassParent implements InterfaceOne,
|
public class ExampleClass extends ExampleClassParent implements InterfaceOne,
|
||||||
InterfaceTwo {
|
InterfaceTwo {
|
||||||
@Override
|
@Override
|
||||||
public void InterfaceOneMethod() {
|
public void InterfaceOneMethod() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void InterfaceTwoMethod() {
|
public void InterfaceTwoMethod() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abstract Classes
|
// Abstract Classes
|
||||||
@ -530,56 +530,56 @@ public class ExampleClass extends ExampleClassParent implements InterfaceOne,
|
|||||||
|
|
||||||
public abstract class Animal
|
public abstract class Animal
|
||||||
{
|
{
|
||||||
public abstract void makeSound();
|
public abstract void makeSound();
|
||||||
|
|
||||||
// Method can have a body
|
// Method can have a body
|
||||||
public void eat()
|
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.
|
// Note: We can access private variable here.
|
||||||
age = 30;
|
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
|
// a variable is implicitly final and hence has
|
||||||
// to be initialized.
|
// to be initialized.
|
||||||
protected int age;
|
protected int age;
|
||||||
|
|
||||||
public void printAge()
|
public void printAge()
|
||||||
{
|
{
|
||||||
System.out.println(age);
|
System.out.println(age);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Abstract classes can have main function.
|
// Abstract classes can have main function.
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
System.out.println("I am abstract");
|
System.out.println("I am abstract");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Dog extends Animal
|
class Dog extends Animal
|
||||||
{
|
{
|
||||||
// Note still have to override the abstract methods in the
|
// Note still have to override the abstract methods in the
|
||||||
// abstract class.
|
// abstract class.
|
||||||
@Override
|
@Override
|
||||||
public void makeSound()
|
public void makeSound()
|
||||||
{
|
{
|
||||||
System.out.println("Bark");
|
System.out.println("Bark");
|
||||||
// age = 30; ==> ERROR! age is private to 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
|
// @Override annotation here, since java doesn't allow
|
||||||
// overriding of static methods.
|
// overriding of static methods.
|
||||||
// What is happening here is called METHOD HIDING.
|
// What is happening here is called METHOD HIDING.
|
||||||
// Check out this awesome SO post: http://stackoverflow.com/questions/16313649/
|
// Check out this awesome SO post: http://stackoverflow.com/questions/16313649/
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
Dog pluto = new Dog();
|
Dog pluto = new Dog();
|
||||||
pluto.makeSound();
|
pluto.makeSound();
|
||||||
pluto.eat();
|
pluto.eat();
|
||||||
pluto.printAge();
|
pluto.printAge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final Classes
|
// Final Classes
|
||||||
@ -595,23 +595,23 @@ class Dog extends Animal
|
|||||||
// extended.
|
// extended.
|
||||||
public final class SaberToothedCat extends Animal
|
public final class SaberToothedCat extends Animal
|
||||||
{
|
{
|
||||||
// Note still have to override the abstract methods in the
|
// Note still have to override the abstract methods in the
|
||||||
// abstract class.
|
// abstract class.
|
||||||
@Override
|
@Override
|
||||||
public void makeSound()
|
public void makeSound()
|
||||||
{
|
{
|
||||||
System.out.println("Roar");
|
System.out.println("Roar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final Methods
|
// Final Methods
|
||||||
public abstract class Mammal()
|
public abstract class Mammal()
|
||||||
{
|
{
|
||||||
// Final Method Syntax:
|
// Final Method Syntax:
|
||||||
// <access modifier> final <return type> <function name>(<args>)
|
// <access modifier> final <return type> <function name>(<args>)
|
||||||
|
|
||||||
// Final methods, like, final classes cannot be overridden by a child class,
|
// Final methods, like, final classes cannot be overridden by a child class,
|
||||||
// and are therefore the final implementation of the method.
|
// and are therefore the final implementation of the method.
|
||||||
public final boolean isWarmBlooded()
|
public final boolean isWarmBlooded()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user