This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task13.task1314; | |
import java.awt.*; | |
import static java.awt.Color.GRAY; | |
/* | |
Большая лисица — это такая лисица | |
*/ | |
public class Correct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultipleInheritance { | |
public static void main(String[] args) throws Exception {} | |
interface Person { | |
void use(Person person); | |
void startToWork();} | |
interface Workable { | |
boolean wantsToGetExtraWork();} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BeerInBar { | |
public static void main(String[] args) throws Exception {} | |
public interface Drink { | |
void askMore(String message); | |
void sayThankYou(); | |
boolean isReadyToGoHome();} | |
public interface Alcohol extends Drink { | |
boolean READY_TO_GO_HOME = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MinAndIndex { | |
public static void main(String[] args) throws Exception { | |
int[] data = new int[]{1, 2, 3, 5, -2, -8, 0, 77, 5, 5}; | |
Pair<Integer, Integer> result = getMinimumAndIndex(data); | |
System.out.println("Minimum is " + result.x); | |
System.out.println("Index of minimum element is " + result.y);} | |
public static Pair<Integer, Integer> getMinimumAndIndex(int[] array) { | |
if (array == null || array.length == 0) { | |
return new Pair<Integer, Integer>(null, null);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Implementation { | |
public static void main(String[] args) {} | |
public interface Fly { | |
public void fly();} | |
public interface Move { | |
public void move();} | |
public interface Eat { | |
public void eat();} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreeMAX { | |
public static void main(String[] args) { | |
} | |
public static int max(int a, int b){return Math.max(a, b);} | |
public static long max(long a, long b){return Math.max(a, b);} | |
public static double max(double a, double b){return (a > b)? a : b;} | |
} | |
/*Три метода и максимум | |
Написать public static методы: int max(int, int), long max(long, long), double max(double, double). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MethodOverloading { | |
public static void main(String[] args) { | |
Integer b = 1000; | |
print(10); | |
print(b); // method overloading with Integer parameter | |
} | |
public static void print(int a){} | |
public static void print(Integer b){} | |
} | |
/*Int и Integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PolymorphismInstanceof { | |
public static void main(String[] args) { | |
System.out.println(getObjectType(new Cow())); | |
System.out.println(getObjectType(new Dog())); | |
System.out.println(getObjectType(new Whale())); | |
System.out.println(getObjectType(new Pig()));} | |
public static String getObjectType(Object o) { | |
if(o instanceof Cow) return "Корова"; // we`re checking "o" instances of "Cow" or no | |
if (o instanceof Dog) return "Собака"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Polymorphism { | |
public static void main(String[] args) { | |
Cow cow = new Whale(); | |
System.out.println(cow.getName()); | |
} | |
public static class Cow { | |
public String getName() { | |
return "I`m a cow"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task09.task0927; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Set; | |
public class FromMapToSet { | |
public static void main(String[] args) { | |
Map<String, Cat> map = createMap(); |
NewerOlder