[JAVA-621] core-java-lang-oop-inheritance module
* Creation * Moved code from https://www.baeldung.com/java-anonymous-classes * Moved code from www.baeldung.com/java-polymorphism * Moved code from www.baeldung.com/java-inheritance * Moved code from www.baeldung.com/java-variable-method-hiding * Moved code from https://www.baeldung.com/java-type-casting * Moved code from https://www.baeldung.com/java-super * Moved code from www.baeldung.com/java-interfaces * Moved code from www.baeldung.com/java-abstract-class * Moved code from www.baeldung.com/java-inner-interfaces * Moved article references to the new README.md
This commit is contained in:
@@ -4,6 +4,4 @@ This module contains articles about Object-oriented programming (OOP) in Java
|
||||
|
||||
### Relevant Articles:
|
||||
- [Pass-By-Value as a Parameter Passing Mechanism in Java](https://www.baeldung.com/java-pass-by-value-or-pass-by-reference)
|
||||
- [Guide to the super Java Keyword](https://www.baeldung.com/java-super)
|
||||
- [Java Interfaces](https://www.baeldung.com/java-interfaces)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-oop-2)[[More -->]](/core-java-modules/core-java-lang-oop-4)
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public interface Box extends HasColor {
|
||||
int getHeight();
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public class Employee {
|
||||
|
||||
private double salary;
|
||||
|
||||
public double getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(double salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.baeldung.interfaces;
|
||||
|
||||
public interface HasColor {
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
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!!");
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public interface Fly {
|
||||
|
||||
void fly();
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public interface Transform {
|
||||
|
||||
void transform();
|
||||
|
||||
default void printSpecs(){
|
||||
System.out.println("Transform Specification");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.baeldung.interfaces.multiinheritance;
|
||||
|
||||
public abstract class Vehicle implements Transform {
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public class Circle implements Shape {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Circle";
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public interface Shape {
|
||||
|
||||
String name();
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.baeldung.interfaces.polymorphysim;
|
||||
|
||||
public class Square implements Shape {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "Square";
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.keyword;
|
||||
|
||||
import com.baeldung.keyword.superkeyword.SuperSub;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/14/2018.
|
||||
*/
|
||||
public class KeywordDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SuperSub child = new SuperSub("message from the child class");
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.keyword.superkeyword;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/14/2018.
|
||||
*/
|
||||
public class SuperBase {
|
||||
|
||||
String message = "super class";
|
||||
|
||||
public SuperBase() {
|
||||
}
|
||||
|
||||
public SuperBase(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void printMessage() {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.keyword.superkeyword;
|
||||
|
||||
/**
|
||||
* Created by Gebruiker on 5/15/2018.
|
||||
*/
|
||||
public class SuperSub extends SuperBase {
|
||||
|
||||
String message = "child class";
|
||||
|
||||
public SuperSub(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SuperSub() {
|
||||
super.printMessage();
|
||||
printMessage();
|
||||
}
|
||||
|
||||
public void getParentMessage() {
|
||||
System.out.println(super.message);
|
||||
}
|
||||
|
||||
public void printMessage() {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user