Skip to content

Instantly share code, notes, and snippets.

@sairajm

sairajm/Circle.java

Created Apr 8, 2021
Embed
What would you like to do?
Java packages example
package com.example.shapes;
public class Circle implements Shapes {
@Override
public String getShape() {
return "Circle";
}
@Override
public String getColor() {
return "Red";
}
}
package com.example.tools;
public class Hammer implements Tools {
@Override
public String getTool() {
return "Hammer";
}
@Override
public String getSize() {
return "7";
}
}
import com.example.shapes.Circle;
import com.example.shapes.Shapes;
import com.example.shapes.Square;
import com.example.tools.Hammer;
import com.example.tools.Tools;
import com.example.tools.Wrench;
public class Main {
public static void main(String args[]) {
Shapes circle = new Circle();
Shapes square = new Square();
Tools hammer = new Hammer();
Tools wrench = new Wrench();
}
}
package com.example.shapes;
public interface Shapes {
public String getShape();
public String getColor();
}
package com.example.shapes;
public class Square implements Shapes {
@Override
public String getShape() {
return "Square";
}
@Override
public String getColor() {
return null;
}
}
package com.example.tools;
public interface Tools {
public String getTool();
public String getSize();
}
package com.example.tools;
public class Wrench implements Tools {
@Override
public String getTool() {
return "Wrench";
}
@Override
public String getSize() {
return "6";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment