Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Wojtek on 2017-04-02.
- */
- public class Main {
- public static void main(String[] args) throws CloneNotSupportedException{
- Punkt punkt = new Punkt(0, 0);
- Odcinek odcinek = new Odcinek(punkt, punkt);
- Odcinek odcinek1 = (Odcinek) odcinek.clone();
- System.out.println(odcinek.getStart().getX());
- System.out.println(odcinek1.getStart().getX());
- System.out.println("Porównanie "+(odcinek==odcinek1));
- System.out.println(odcinek.getStart().getX());
- System.out.println(odcinek.getStart().getY());
- System.out.println("Porównanie "+(odcinek.equals(odcinek1)));
- }
- }
- /**
- * Created by Wojtek on 2017-04-02.
- */
- public class Punkt implements Cloneable{
- private int x = 0;
- private int y = 0;
- public Punkt(int x, int y){
- this.x = x;
- this.y = y;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public void setX(int x) {
- this.x = x;
- }
- public void setY(int y) {
- this.y = y;
- }
- @Override
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
- /**
- * Created by Wojtek on 2017-04-02.
- */
- public class Odcinek implements Cloneable{
- private Punkt start = null;
- private Punkt koniec = null;
- private Odcinek(){
- }
- public Odcinek(Punkt start, Punkt koniec){
- this.start = start;
- this.koniec = koniec;
- }
- public Punkt getStart() {
- return start;
- }
- public Punkt getKoniec() {
- return koniec;
- }
- public void setStart(Punkt start) {
- this.start = start;
- }
- public void setKoniec(Punkt koniec) {
- this.koniec = koniec;
- }
- @Override
- public Object clone() throws CloneNotSupportedException {
- Odcinek odcinek = new Odcinek();
- odcinek.setStart((Punkt) getStart().clone());
- odcinek.setKoniec((Punkt) getKoniec().clone());
- return odcinek;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement