Advertisement
Fourteen98

classes and subclasses

Sep 12th, 2021
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package com.company;
  2.  
  3. // main class
  4. class Birds {
  5.     String color;
  6.     double size;
  7.     String name;
  8.     double weight;
  9.  
  10.     void Flying(){
  11.         System.out.println("I can fly");
  12.     }
  13.  
  14.     void Breathing(){
  15.         System.out.println("I can breath");
  16.     }
  17.  
  18.     void Eating(){
  19.         System.out.println("I can eat");
  20.     }
  21.  
  22.     void Reproducing(){
  23.         System.out.println("I can reproduce");
  24.     }
  25.  
  26. }
  27.  
  28. // subclass inherit from Birds
  29. class Eagle extends Birds{
  30.     String sharpClaws;
  31.  
  32.     void hovering(){
  33.         System.out.println("I can hover");
  34.     }
  35.  
  36. }
  37.  
  38.  
  39. // subclass inherit from Birds
  40. public class Parrot extends Birds{
  41.     String curvedBeak;
  42.  
  43.  
  44.     void talking(){
  45.         System.out.println("I can talk");
  46.     }
  47.  
  48.     public static void main(String[] args) {
  49.         Parrot cuckatoos = new Parrot();
  50.         cuckatoos.color =  "Green";
  51.         cuckatoos.Eating();
  52.         cuckatoos.Reproducing();
  53.  
  54.  
  55.         Eagle goldenEagle = new Eagle();
  56.         goldenEagle.color = "gold";
  57.         goldenEagle.Breathing();
  58.  
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement