gle Nctepad File Edit Format View Help public class Triangle extends Shape t pri
ID: 3871786 • Letter: G
Question
gle Nctepad File Edit Format View Help public class Triangle extends Shape t private double side1; private double side2; private double side3; public Triangle) f this(1.e, 1.e, 1.0); public Triangle(double side1, double side2, double sidea) ( setside1 (side1); setside2(side2); setside3 (side3); public double getArea) ( // Heron's formula double p - (getside1) + getside2) return area; getside30)/2.8; double area Math.sqrt(p*(p-getside1o) (p-getside2()) (p-getside303))i public string tostring) f return super.tostring) I'n a Triangle" public double getside1) f return side1; public void setside1(double side1) ( this.side1 side1; public double getside2) ( return side2; public void setside2(double side2) t this.side2 - side2 public double getside3() return side3; oublsc voxd setsides(double sidea ) ( this sidea - sides; O Type here to searchExplanation / Answer
Vehicle/Engline :
1)Vehicle is a bigger group like a generalize one which includes many sub parts like wheel , brakes,suspension,etc. And,engine is one of the sub parts of the Vehicle
2) Super
Child
3) is super class of
4) This type of relationship is implemented in JAVA through inheritance where a class can inherit the properties of the other class
Shapes:-
1)Shape is the super class and Circle is the child class.Which means Circle class derives the properties of class Shape and implement it
2)Parent
Child
3)Inherits
4)Inheritence
6)Width and length are instance variables as they are private .They can only be used in Rectangle class only
7)numShapes is an static variable.We can access it through it's class name.
8)We can create an object/instances of those classes and we can use them without changing the visibility
TestShapes.java
1)Object variables / Instance variables
2)Only 1 constructor is called
3)2 constructors are called i.e first one is the Shape constructor and other one is the circle constructor.This process which accounts for this behaviour is inheritence
4)toString() in class shape is invoked.The technical term for this to happen in inheritence
5)
b)getArea() of triangle class will be invoked.This process is called polymorphism .Here,the priority comes first.So,for a triangle class getArea() of triangle class is local and have more priority when compare to getArea() of shape class.Therefore,getArea() of triangle class is invoked
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.