29 / 53

Scala - Assessment - Declare a class

Let's try to write a simple class.

This would be class named Student having below members.

  • name of type String
  • sex of type Char (M / F)
  • grade of type Integer (ex - 1, 2, 3, 4 etc)
  • age of type of Integer (ex - 7, 10, 13 etc)

Using the resulting class, one should be able to instantiate new objects like below:

var stu1 = new Student("John Doe", 'M', 15, 23 );

The class members of the object should be accessible as below:

var name_stu =
var sex_stu =
var grade_stu = stu1.grade
var age_stu = stu1.age
  • Switch to the Jupyter tab.

  • Write the code of the class in Jupyter.

  • Press Shift+Enter to execute the code.

  • Try to create objects of the class and make sure that it works as per the above requirements.

  • Click on "Submit Answer".

Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...