OCA Quiz 2A

  • class Runner extends Person{
      public void run(){
         System.out.println("running");
         eat();
       }
    }

    class Person extends Runner{
      private int age;
      private String name;
       Person(){
         eat();
        run();
       }
      public void eat(){
         System.out.println("eating");
       }
      public static void main(String[] args){
         Person p = new Person();
      }
    }
  • class Runner extends Person{
       public static void run(){
         System.out.print("%s is running",name);
        eat();
      }
    }

    class Person {
       private int age;
      private String name;
      Person(String name){
         Runner.run();
       }
       public void eat(){
         System.out.println("eating");
       }
       public static void main(String[] args){
         Person p = new Person("John");
      }
    }
  • class Runner extends Person{
       public void run(){
         System.out.printf("%s is running",getName());
       }
    }

    class Person {
       private int age;
      private String name;
       String getName(){
         // n1
      }
       Person(){}
       Person(String name){
         new Runner().run();
      }
      public static void main(String[] args){
         Person p = new Person("John");
      }
    }
  • class Runner extends Person{
       public void run(){
         System.out.printf("%s is running",getName());
      }
    }

    class Person {
       private int age;
       private String name;
       String getName(){
         return name;
       }
       Person(String name){
         this.name = name;
         new Runner().run();
       }
      public static void main(String[] args){
         Person p = new Person("John");
       }
    }
  • class Runner extends Person{
      public void run(){
         System.out.printf("%s is running",getName());
      }
    }

    class Person {
       private int age;
      private String name;
       String getName(){
         return name;
      }
      Person(){}
      Person(String name){
         this.name = name;
         new Runner().run();
       }
       public static void main(String[] args){
         Person p = new Person("John");
       }
    }
  • class Food{
    private int calories;
    int getCalories(){
    return calories;
    }
    Food(int calories){
    this.calories = calories;
    }
    }

    class Person{
    private int calorieTotal;
    private List stomache = new ArrayList<>();
    boolean eat(Food yums){
    boolean ate = true;
    if(calorieTotal < 10000){
    System.out.println("*eats*");
    stomache.add(yums);
    }
    else{
    ate = false;
    System.out.println("too full to eat");
    stomache.remove(0);
    }
    return ate;
    }
    public static void main(String[] args){
    Person p = new Person(); while(p.eat(new Food(new Random.nextInt(2000))))
    ;System.out.println("one hour later");
    while(p.eat(new Food(new Random.nextInt(2000))));
    }
    }
  • final class Animal{
       private String name;
      Animal(String name){
         name = name;
       }
       String getName(){
         return name;
       }
    }

    class Cat extends Animal{
       void sleep(){
         System.out.println(getName()+" the pet cat sleeps");
       }
       public static void main(String[] args){
         Cat c = new Cat("Fluffy");
       }
    }
  • final class Animal{
       private String name;
      Animal(String name){
         name = name;
       }
      String getName(){
         return name;
      }
    }

    class Cat extends Animal{
      Cat(String name){
         super(name);
       }
      void sleep(){
         System.out.println(getName()+" the pet cat sleeps");
       }
       public static void main(String[] args){
         Cat c = new Cat("Fluffy");
         c.sleep();
      }
    }
  • class Animal{
       private String name;
      Animal(String name){
         this.name = name;
       }
      String getName(){
         return name;
       }
       public void sleep(){
         System.out.println(getName()+" the pet sleeps");
       }
    }

    class Cat extends Animal{
       Cat(String name){
         super(name);
       }
      void sleep(){
        System.out.println(getName()+" the pet cat sleeps");
      }
       public static void main(String[] args){
         Animal c = new Cat("Fluffy");
         c.sleep();
       }
    }
  • class Animal{
       private String name;
      Animal(String name){
         name = name;
       }
       String getName(){
         return name;
       }
       public void sleep(){
         System.out.println(getName()+" the pet sleeps");
       }
    }

    class Cat extends Animal{
      Cat(String name){
         super(name);
       }
       public void sleep(){
         System.out.println(getName()+" the pet cat sleeps");
       }
       public static void main(String[] args){
         Animal c = new Cat("Fluffy");
         c.sleep();
       }
    }