Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package animals;
- /**
- *
- * @author fmi
- */
- public class Animals {
- public interface Calculatable {
- double calculateFactorial(double x);
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Animal[] myAnimals = new Animal[5];
- // upcasting
- Animal fluffy = new Cat();
- Animal sharo = new Dog();
- // Cat fluffyStatic = new Cat();
- // Cat.makeNoise();
- // Animal.makeNoise();
- // downcasting back to the original type.
- Cat fluffy2 = (Cat)fluffy;
- fluffy2.doOnlyForCat();
- ((Cat) fluffy).doOnlyForCat();
- myAnimals[0] = fluffy;
- myAnimals[1] = sharo;
- myAnimals[0].makeNoise();
- myAnimals[1].makeNoise();
- Dog sharo1 = new Dog();
- System.out.println(sharo1.favoriteFood);
- double price;
- Person stoyan = new Person(50, "Stoyan");
- stoyan.introduceYourSelf();
- class LocalClass {
- public String test;
- }
- LocalClass myLocalClass = new LocalClass();
- Object myAnonymous = new Object(){
- @Override
- public String toString() {
- return "{Anonymous" + '}';
- }
- };
- System.out.println(myAnonymous.toString());
- //Calculatable myCalculation = (x) -> return x*x*x;
- // or
- Calculatable myAnonymous1 = new Calculatable() {
- @Override
- public double calculateFactorial(double x) {
- return x;
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement