Java Shape Quiz | Sololearn: Learn to code for FREE!

0

Java Shape Quiz

Can anyone elaborate on the following line of code from the "Java Shapes Project" (in More On Classes): Square a = new Square(x); Circle b = new Circle(y); Specifically, I'm not understanding the "Square a" and "Circle b" parts??? Is it just assigning "Square(int x)" to "a" ? So when it's called later in "a.area()". If so, couldn't someone write "Circle a = new Circle(x);" How would it know if "a.area()" was for the Circle or Square???

9/14/2021 11:09:04 PM

Joel Mahaffey

1 Answer

New Answer

0

Square a = new Square(x); it creates object of type Square and its constructor can use value of x then this new Object is assigned to variable a of type Square q2: no, if type of a is declared yet q3: because a has only one type, it is not problem