Skip to content

Instantly share code, notes, and snippets.

@sairajm
Created April 8, 2021 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sairajm/0d819c00240435f223472e76ef8d145b to your computer and use it in GitHub Desktop.
Save sairajm/0d819c00240435f223472e76ef8d145b to your computer and use it in GitHub Desktop.
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