moving code from java-core to java-core-lang (#6084)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public interface Box extends HasColor {
|
||||
int getHeight();
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private double salary;
|
||||
|
||||
public double getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(double salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class EmployeeSalaryComparator implements Comparator<Employee> {
|
||||
|
||||
@Override
|
||||
public int compare(Employee employeeA, Employee employeeB) {
|
||||
if (employeeA.getSalary() < employeeB.getSalary()) {
|
||||
return -1;
|
||||
} else if (employeeA.getSalary() > employeeB.getSalary()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public interface HasColor {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public class Car implements Fly,Transform {
|
||||
|
||||
@Override
|
||||
public void fly() {
|
||||
System.out.println("I can Fly!!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform() {
|
||||
System.out.println("I can Transform!!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public interface Fly {
|
||||
|
||||
void fly();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public interface Transform {
|
||||
|
||||
void transform();
|
||||
|
||||
default void printSpecs(){
|
||||
System.out.println("Transform Specification");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public abstract class Vehicle implements Transform {
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public class Circle implements Shape {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Circle";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainTestClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Shape> shapes = new ArrayList<>();
|
||||
Shape circleShape = new Circle();
|
||||
Shape squareShape = new Square();
|
||||
|
||||
shapes.add(circleShape);
|
||||
shapes.add(squareShape);
|
||||
|
||||
for (Shape shape : shapes) {
|
||||
System.out.println(shape.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public interface Shape {
|
||||
|
||||
String name();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public class Square implements Shape {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Square";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user