(base) MAC:Mon Nov 09:09:37:shapeB> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> /open Shape.java jshell> /open Rectangle.java jshell> Rectangle r = new Rectangle(6,8); r ==> Rectangle@1d56ce6a jshell> r.diameter() $4 ==> 10.0 jshell> r.perimeter() $5 ==> 28.0 jshell> r.area() $6 ==> 48.0 jshell> Shape s = new Rectangle(3,4); s ==> Rectangle@238e0d81 jshell> s.area() $8 ==> 12.0 jshell> //Rectangle is a subtype of Shape jshell> //A variable of a given type can point at an object/ jshell> //of any subtype. jshell> Object o = new Rectangle(6,8); o ==> Rectangle@728938a9 jshell> o o ==> Rectangle@728938a9 jshell> o.area() | Error: | cannot find symbol | symbol: method area() | o.area() | ^----^ jshell> //Visibility Principle: The type of a variable jshell> //dictates what methods are visible. jshell> /exit | Goodbye (base) MAC:Mon Nov 09:09:42:shapeB> vi Rectangle.java (base) MAC:Mon Nov 09:09:43:shapeB> javac Rectangle.java (base) MAC:Mon Nov 09:09:43:shapeB> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> Object o = new Rectangle(3,4); | Error: | cannot find symbol | symbol: class Rectangle | Object o = new Rectangle(3,4); | ^-------^ jshell> /open Shape.java jshell> /open Rectangle.java jshell> Object o = new Rectangle(3,4); o ==> Rectangle(3.0, 4.0) jshell> o.toString() $4 ==> "Rectangle(3.0, 4.0)" jshell> //Delegation: Method calls are delegated to the jshell> //object. jshell> /exit | Goodbye (base) MAC:Mon Nov 09:09:45:shapeB> vi Circle.java (base) MAC:Mon Nov 09:09:49:shapeB> javac *.java Circle.java:6: error: ';' expected this.radius = radius ^ 1 error (base) MAC:Mon Nov 09:09:49:shapeB> !vi vi Circle.java (base) MAC:Mon Nov 09:09:49:shapeB> !javac javac *.java (base) MAC:Mon Nov 09:09:49:shapeB> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> Shape s = new Rectangle(6,8); | Error: | cannot find symbol | symbol: class Shape | Shape s = new Rectangle(6,8); | ^---^ | Error: | cannot find symbol | symbol: class Rectangle | Shape s = new Rectangle(6,8); | ^-------^ jshell> /open Shape.java jshell> /open Circle.java jshell> /open Rectangle.java jshell> Shape s = new Rectangle(6,8); s ==> Rectangle(6.0, 8.0) jshell> s.area() $5 ==> 48.0 jshell> s = new Circle(10); s ==> Circle@5010be6 jshell> s.area() $7 ==> 314.1592653589793 jshell> /quit | Invalid command: /quit | Type /help for help. jshell> vi Triangle.java | Error: | ';' expected | vi Triangle.java; | ^ jshell> /exit | Goodbye (base) MAC:Mon Nov 09:09:52:shapeB> vi Triangle.java (base) MAC:Mon Nov 09:10:02:shapeB> javac Triangle.jva error: Class names, 'Triangle.jva', are only accepted if annotation processing is explicitly requested 1 error (base) MAC:Mon Nov 09:10:02:shapeB> javac Triangle.java (base) MAC:Mon Nov 09:10:02:shapeB> !vi vi Triangle.java (base) MAC:Mon Nov 09:10:03:shapeB> javac Triangle.java (base) MAC:Mon Nov 09:10:03:shapeB> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> /open Shape.java jshell> /open Rectangle.java jshell> /open Triangle.java jshell> /open Circle.java jshell> Shape s = new Triangle(3,4,5); s ==> Triangle(3.0, 4.0, 5.0) jshell> s.area() $6 ==> 6.0 jshell> s.diameter() $7 ==> 5.0 jshell> s.perimeter() $8 ==> 12.0 jshell> s = new Triangle(3,6,7); s ==> Triangle(3.0, 6.0, 7.0) jshell> s.area() $10 ==> 8.94427190999916 jshell> s.diameter() $11 ==> 7.0 jshell> s.perimeter9) | Error: | ';' expected | s.perimeter9) | ^ | Error: | cannot find symbol | symbol: variable perimeter9 | s.perimeter9) | ^----------^ jshell> s.perimeter() $12 ==> 16.0 jshell> /exit | Goodbye (base) MAC:Mon Nov 09:10:06:shapeB> ls Circle.class Rectangle.class Shape.class Triangle.class Circle.java Rectangle.java Shape.java Triangle.java (base) MAC:Mon Nov 09:10:06:shapeB> vi Polygon.java (base) MAC:Mon Nov 09:10:08:shapeB> vi Rectangle.java (base) MAC:Mon Nov 09:10:08:shapeB> vi Triangle.java (base) MAC:Mon Nov 09:10:09:shapeB> javac *.java (base) MAC:Mon Nov 09:10:09:shapeB> jshell | Welcome to JShell -- Version 14.0.1 | For an introduction type: /help intro jshell> Shape s = new Triangle(4,5,6); | Error: | cannot find symbol | symbol: class Shape | Shape s = new Triangle(4,5,6); | ^---^ | Error: | cannot find symbol | symbol: class Triangle | Shape s = new Triangle(4,5,6); | ^------^ jshell> /open Shape.java jshell> /open Triangle.java jshell> /open Circle.jva | File 'Circle.jva' for '/open' is not found. jshell> /open Circle.java jshell> /open Polygon.java jshell> /open /Rectangle.java | File '/Rectangle.java' for '/open' is not found. jshell> /open Rectangle.java jshell> Shape s = new Triangle(4,5,6); s ==> Triangle(4.0, 5.0, 6.0) jshell> s.area() $7 ==> 9.921567416492215 jshell> s.numSides() | Error: | cannot find symbol | symbol: method numSides() | s.numSides() | ^--------^ jshell> Polygon p = s; | Error: | incompatible types: Shape cannot be converted to Polygon | Polygon p = s; | ^ jshell> Polygon p = new Triangle(4,5,6); p ==> Triangle(4.0, 5.0, 6.0) jshell> p.numSides() $9 ==> 3 jshell> p.area() $10 ==> 9.921567416492215 jshell> p.perimeter() $11 ==> 15.0 jshell> p.diameter() $12 ==> 6.0 jshell> ArrayList al = new ArrayList(); al ==> [] jshell> al.add(new Circle(10)); $14 ==> true jshell> al.add(new Rectangle(10,10)); $15 ==> true jshell> al.add(new Triangle(3,4,6)); $16 ==> true jshell> al al ==> [Circle@246b179d, Rectangle(10.0, 10.0), Triangle(3.0, 4.0, 6.0)] jshell> double total = 0 total ==> 0.0 jshell> for(Shape s: al) ...> { jshell> for(Shape s: al) ...> {b again to see all possible completions; total possible completions: 559> ...> out += s.area(); ...> } | Error: | cannot find symbol | symbol: variable out | out += s.area(); | ^-^ jshell> for(Shape s: al) ...> { ...> total += s.area(); ...> } jshell> total total ==> 419.49194761090473