๐Ÿ”’ Closed Pasok kanaman

Status
Not open for further replies.
pano ba to ma run gamut Java compiler
Java:
interface Polygon {
  void getArea();

  // default method
  default void getSides() {
    System.out.println("I can get sides of a polygon.");
  }
}

// implements the interface
class Rectangle implements Polygon {
  public void getArea() {
    int length = 6;
    int breadth = 5;
    int area = length * breadth;
    System.out.println("The area of the rectangle is " + area);
  }

  // overrides the getSides()
  public void getSides() {
    System.out.println("I have 4 sides.");
  }
}

// implements the interface
class Square implements Polygon {
  public void getArea() {
    int length = 5;
    int area = length * length;
    System.out.println("The area of the square is " + area);
  }
}

class Main {
  public static void main(String[] args) {

    // create an object of Rectangle
    Rectangle r1 = new Rectangle();
    r1.getArea();
    r1.getSides();

    // create an object of Square
    Square s1 = new Square();
    s1.getArea();
    s1.getSides();
  }
}
 
OOP sir? ano pong Problem?
1615816504837.webp
 

Attachments

  • Screenshot_2021-03-15-21-56-45-01_7885c407ff790600b0e797e3f33df4de.webp
    Screenshot_2021-03-15-21-56-45-01_7885c407ff790600b0e797e3f33df4de.webp
    73 KB · Views: 17
  • Screenshot_2021-03-15-21-56-42-63_7885c407ff790600b0e797e3f33df4de.webp
    Screenshot_2021-03-15-21-56-42-63_7885c407ff790600b0e797e3f33df4de.webp
    54.5 KB · Views: 15
Java:
public class Main
{
    public static void main(String[] args) {
        // create an object of Rectangle
        Rectangle r1 = new Rectangle();
        r1.getArea();
        r1.getSides();

        // create an object of Square
        Square s1 = new Square();
        s1.getArea();
        s1.getSides();
    }
}
        interface Polygon {
            void getArea();

            // default method
            default void getSides() {
            System.out.println("I can get sides of a polygon.");
    }
}

            // implements the interface
        class Rectangle implements Polygon {
        public void getArea() {
        int length = 6;
        int breadth = 5;
        int area = length * breadth;
            System.out.println("The area of the rectangle is " + area);
    }

        // overrides the getSides()
        public void getSides() {
            System.out.println("I have 4 sides.");
    }
}

        // implements the interface
        class Square implements Polygon {
        public void getArea() {
        int length = 5;
        int area = length * length;
            System.out.println("The area of the square is " + area);
    }
}

patry po to..
 
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 370
    Views
  • 2
    Participants
Last reply from:
G O Z A R U

Online now

Members online
1,109
Guests online
897
Total visitors
2,006

Forum statistics

Threads
2,277,021
Posts
28,973,765
Members
1,229,687
Latest member
gsby1440xd
Back
Top