Last active
August 29, 2015 14:19
-
-
Save wbars/4c10ee23c4be8884d8fd to your computer and use it in GitHub Desktop.
Соблюдение контракта
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
/** | |
* Created by wannabe on 12.04.15. | |
*/ | |
interface Animal | |
{ | |
int getLegsCount(); | |
animal move(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error:(13, 32) java: cannot find symbol | |
symbol: method getPosition() | |
location: variable robert of type com.example.helloworld.animal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
/** | |
* Created by wannabe on 12.04.15. | |
*/ | |
public class Main | |
{ | |
public static void main(String[] args) | |
{ | |
animal robert = new Monkey(); | |
System.out.print(robert.getLegsCount()); | |
robert.move(); | |
System.out.print(robert.getPosition()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.helloworld; | |
/** | |
* Created by wannabe on 12.04.15. | |
*/ | |
public class Monkey implements Animal | |
{ | |
protected int position = 2; | |
public int getLegsCount() | |
{ | |
return 2; | |
} | |
public animal move() | |
{ | |
this.position += 2; | |
return this; | |
} | |
public int getPosition() | |
{ | |
return this.position; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment