Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

AL. (5 marks) Fill in the blanks Use the most suitable words given in the box su

ID: 3739352 • Letter: A

Question

AL. (5 marks) Fill in the blanks Use the most suitable words given in the box superchss private ymorphism child chss Information hding encapsulation extends Tinal super masking a. The keywords that creates inheritance is b. whaa ?dclass method has he same name and argument types as a superclass method, he subclass method can override the superclass method. This concept is known as C. When you instantiate an object that is a member of a subclass, the constructor is cxecutes first d. A subelass cannot override static methods and e. In Java, the concept of keeping data private is known as A2.(20 marks) methods defined in a supercla a Daw a U/MI. class diagram named Rectangleshape to represent a rectangle. The class contains Two doubke data fields namod width and height hat specify the width and height of the rectangle A no-arg constructor that creates a default rectangle A constructor that creates a rectangle with the specified width and height A method namod getAreaO that retums the area of this rectangle A method named getPerineter O that returns the perimeter (7 marks) besod on the anr in part (a, implement the class (13 marks)

Explanation / Answer

A1) Fill in the blanks

    a) extends

Explanation:-

"extends" is the key word used for inheritance.

eg:-class Bycycle{}//Base class

    class scooby extends Bycycle{}//derived class

----------------------------------------------------------------------------------------------------------

b) Information Hiding

Explanation:-

Overriding uses same name and the types of arguments as per the user requirements.

which hide the original data.

---------------------------------------------------------------------------------------------------------------------

c) Superclass

Explanation:-

When you call the same method in subclass and superclass,both execute,but first always execute superclass.

----------------------------------------------------------------------------------------------------------------------------------------------------------------

d) final

Explanation:-

final and static variables or methods of a class is more private,so they can't be overriden.

-----------------------------------------------------------------------------------------------------------------------------------------------

e) Encapsulation

Explanation:-

The process of keeping data in a closed secure manner is called encapsupation.

----------------------------------------------------------------------------------------------------------------------------------------------

A2) UML diagram & Implementation

a) UML diagram of rectangle

-width:Double

-height:Double

+RectangleShape()

+RectangleShape(width:Double,height:Double)

+getArea():Double

+getPerimeter():Double

-----------------------------------------------------------------------------------------------------------------------------------------------

b) Implementation

ScreenShot

Code:-

//Packages
import java.util.*;
import java.lang.*;
import java.io.*;
//Class RectangleShape
class RectangleShape{
   //Member variables
        double width;
        double height;
   //Methods
   //Default constructor
      public RectangleShape(){
       this(2,2);
      }
      //Costructor with arguments
        public RectangleShape(double width,double height){
           this.width=width;
           this.height=height;
        }
        //Area calculation
        public double getArea(){
           return width * height;
        }
        //Perimeter calculation
        public double getPerimeter(){
           return 2 * (width + height);
        }
      
}
//main class
class Ideone
{
   //main method
   public static void main (String[] args) throws java.lang.Exception
   {
       //default constructor object creation
       RectangleShape rs=new RectangleShape();
       //parameterised constructor object creation
       RectangleShape rshape=new RectangleShape(10,12);
       //Default constructor using to find Area and Perimeter
       System.out.println("Area = "+rs.getArea()+" and Perimeter = "+rs.getPerimeter());
       //Parameterised constructor using to find Area and Perimeter
       System.out.println("Area = "+rshape.getArea()+" and Perimeter = "+rshape.getPerimeter());
   }
  
}

                                         RectangleShape

-width:Double

-height:Double

+RectangleShape()

+RectangleShape(width:Double,height:Double)

+getArea():Double

+getPerimeter():Double

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote