List<Integer> list; list = new ArrayList<Integer>(); //ArrayList LinkedList List, list = new LinkedList<Integer>(); list = new String(); //
public class Fruit { public void eat(){ System.out.println("NomNomNom"); } } class Apple extends Fruit{ public void grow(){ System.out.println("I'm growing"); } public static void main(String[] args) throws InterruptedException { Fruit fruit; fruit = new Apple(); fruit.eat(); // eat , fruit.grow(); //! grow Apple, Fruit } }
public class Fruit { public void eat(){ System.out.println("NomNomNom"); } } class Apple extends Fruit{ public void grow(){ System.out.println("I'm growing"); } public void eat(){ System.out.println("NomAppleNom"); } public void test(){ eat();// super.eat();// } }
public class Fruit { public int eat(){ byte b = 127; return b; // byte b int. } public int grow(){ long l = 42; return l; //! int 42 , // return (int) l; } }
public class Fruit { public Fruit(String str){ System.out.println("Fruit constructor"); } } class Apple extends Fruit{ public Apple(){ super("apple"); System.out.println("Apple's constructor"); } } public class GreenApple extends Apple{ public GreenApple(){ System.out.println("GreenApple's constructor"); }; : Fruit constructor Apple's constructor GreenApple's constructor }
Source: https://habr.com/ru/post/150193/
All Articles