You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/json/parentclasses.json
+9-10Lines changed: 9 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -3,30 +3,29 @@
3
3
"modules": [
4
4
{
5
5
"preparagraph": "In contrast to Java, all values in Scala are objects (including numerical values and functions). Since Scala is class-based, all values are instances of a class.\n\nClass hierarchy is linear, a class can only extend from one parent class:\n",
6
-
"code": "class Worker(val firstName: String, val lastName: String) {}\nclass Employee(override val firstName: String, override val lastName: String,\n val employeeID: Long) extends Worker(firstName, lastName)\nval me = new Employee(\"Name\", \"Yourself\", 1233)\nme.firstName should be(__)\nme.lastName should be(__)",
6
+
"code": "class Soldier(val firstName: String, val lastName: String) {}\nclass Pilot(override val firstName: String, override val lastName: String,\n val squadron: Long) extends Soldier(firstName, lastName)\nval pilot = new Pilot(\"John\", \"Yossarian\", 256)\npilot.firstName should be(__)\npilot.lastName should be(__)",
7
7
"solutions": [
8
-
"\"Name\"",
9
-
"\"Yourself\""
8
+
"\"John\"",
9
+
"\"Yossarian\""
10
10
],
11
11
"postparagraph": ""
12
12
},
13
13
{
14
14
"preparagraph": "A class that extends from another is polymorphic:",
15
-
"code": "class Worker(val firstName: String, val lastName: String) {}\nclass Employee(override val firstName: String, override val lastName: String,\n val employeeID: Long) extends Worker(firstName, lastName)\n\nval me = new Employee(\"Name\", \"Yourself\", 1233)\nval worker: Worker = me\n\nworker.firstName should be(__)\nworker.lastName should be(__)",
15
+
"code": "class Soldier(val firstName: String, val lastName: String) {}\nclass Pilot(override val firstName: String, override val lastName: String,\n val squadron: Long) extends Soldier(firstName, lastName)\n\nval pilot = new Pilot(\"John\", \"Yossarian\", 256)\nval soldier: Soldier = pilot\n\nsoldier.firstName should be(__)\nsoldier.lastName should be(__)",
16
16
"solutions": [
17
-
"\"Name\"",
18
-
"\"Yourself\""
17
+
"\"John\"",
18
+
"\"Yossarian\""
19
19
],
20
20
"postparagraph": ""
21
21
},
22
22
{
23
-
"preparagraph": "An abstract class, as in Java, cannot be instantiated and only inherited:\n\n```\nabstract class Worker(val firstName: String, val lastName: String) {}\n\n// if you uncomment this line, if will fail compilation\n//val worker = new Worker\n```\n\nA class can be placed inside an abstract class just like in java:",
24
-
"code": "abstract class Worker(val firstName: String, val lastName: String) {\n class Assignment(val hours: Long) {\n // nothing to do here. Just observe that it compiles\n }\n}\nclass Employee(override val firstName: String, override val lastName: String,\n val employeeID: Long) extends Worker(firstName, lastName)\n\nval employee = new Employee(\"Name\", \"Yourself\", 2291)\nval assignment = new employee.Assignment(__) //using the employee instance's path, create an assignment for it.\nassignment.hours should be (__)",
23
+
"preparagraph": "An abstract class, as in Java, cannot be instantiated and only inherited:\n\n```\nabstract class Soldier(val firstName: String, val lastName: String) {}\n\n// if you uncomment this line, if will fail compilation\n//val soldier = new Soldier\n```\n\nA class can be placed inside an abstract class just like in java:",
24
+
"code": "abstract class Soldier(val firstName: String, val lastName: String) {\n class Catch(val number: Long) {\n // nothing to do here. Just observe that it compiles\n }\n}\nclass Pilot(override val firstName: String, override val lastName: String,\n val squadron: Long) extends Soldier(firstName, lastName)\n\nval pilot = new Pilot(\"John\", \"Yossarian\", 256)\nval catchNo = new pilot.Catch(22) //using the pilot instance's path, create an catch object for it.\ncatchNo.number should be (__)",
0 commit comments