Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract public class Animal {
- public int nLegs = 0;
- public void numLegs(int nLegs) {
- this.nLegs = nLegs;
- }
- public abstract int getLegs();
- //Constructor
- public Animal (int nLegs) {
- numLegs(nLegs)
- }
- }
- public class Monkey extends Animals {
- public int getLegs(){
- return this.nLegs;
- }
- public monkey(){
- super(2);
- }
- public void saySome(){
- System.out.println("Hello, I am a monkey!");
- }
- }
- public class MainClass{
- public static void main(String []args){
- Animal jay = new Monkey ();
- System.out.println(jay.nLegs);
- /* jay.saySome()*/
- ((Monkey) jay).saySome();
- }
- }
Add Comment
Please, Sign In to add comment