Skip to content

Instantly share code, notes, and snippets.

@wbars
Last active August 29, 2015 14:19
Show Gist options
  • Save wbars/4c10ee23c4be8884d8fd to your computer and use it in GitHub Desktop.
Save wbars/4c10ee23c4be8884d8fd to your computer and use it in GitHub Desktop.
Соблюдение контракта
package com.example.helloworld;
/**
* Created by wannabe on 12.04.15.
*/
interface Animal
{
int getLegsCount();
animal move();
}
Error:(13, 32) java: cannot find symbol
symbol: method getPosition()
location: variable robert of type com.example.helloworld.animal
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());
}
}
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