Close
Close

java question

   arjunanand46

  1. Create a class named 'Shape' with a method to print "This is This is shape". Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape class, both having a method to print "This is rectangular shape" and "This is circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a method to print "Square is a rectangle". Now call the method of 'Shape' and 'Rectangle' class by the object of 'Square' class. 

  • I have the same qustion. [url=https://mumbai.crbtech.in/programmes/software-testing-training-programme/]Software Testing Course in Mumbai[/url]
    - Inglejyoti
  • I have the same question. <a href="https://mumbai.crbtech.in/programmes/software-testing-training-programme/">Software Testing Course in Mumbai</a>
    - Inglejyoti
  • 1. Write a program to print the area of a rectangle to the main method. Creating a Method named 'Area' and a Method name "isRectangle" to check if the length and width of rectangle is valid.
    - myname01

Answers

  •   

    I am writing the code with comments below.

    class Shape{
      public void print_shape(){
        System.out.println("This is shape");
      }
    }
    
    // Rectangle class is subclass of Shape class
    class Rectangle extends Shape{
      public void print_rect(){
        System.out.println("This is rectangular shape");
      }
    }
    
    // Circle class is subclass of Shape class
    class Circle extends Shape{
      public void print_circle(){
        System.out.println("This is circular shape");
      }
    }
    
    // Square class is subclass of Rectangle class
    class Square extends Rectangle{
      public void print_square(){
        System.out.println("Square is a rectangle");
      }
    }
    
    // main class
    class Test{
      public static void main(String[] args){
        Square sq = new Square();  // creating object of Square class
        sq.print_shape();    // Object of Square class calling function of Shape class
        sq.print_rect();    // Object of Square class calling function of Rectangle class
      }
    }
    

     



  •   

    public class shape{
        public void print_shape(){
            System.out.println("This is a shape!");
        }
    }
        class rectangle extends shape{
            public void print_rect(){
                System.out.println("This is rectangle! ");
            }
        }
        class circle extends shape{
            public void print_circle(){
                
            }
        }
        class square extends rectangle{
            public  void print_square(){
                System.out.println("Square is a rectangle");
            }
        }
        
       public class test{
            public static void main(String[] args){
                square sq = new square();
                sq.print_shape();
                sq.print_rect();
            }
        }







  •    seoexpertim

    The main reason i came here https://scholarlyoa.com/how-to-write-essay/ is the outcome of this website. I've never seen anything like this before on the internet. There are no disadvantages.



  •    frederickgragg

    I like Certsboard customer supports they help me to restore my PC while I am studying my certification exams, 220-1001 Prep Questions provides authentic IT Certification exams preparation material guaranteed to make you pass in the first attempt.



Ask Yours
Post Yours
Write your answer