Single Choice Question

  1. Which following statement is wrong about class and object?
    1. Class is the template of many objects.
    2. Object is the instance of one class.
    3. Class define the common properties and methods of many objects.
    4. Object is abstraction of class.
  2. Which way is the wrong way to create an object?
    1. let user = {};
    2. let user = new Object();
    3. let user = User();
    4. let user = new User();
  3. Which is the correct syntax to create a class?
    1. class User {...}
    2. class User(...)
    3. class User;
    4. class User; {...}
  4. What are the major components of a class?
    1. Properties
    2. Methods
    3. Constructor
    4. All of the above
  5. Which way is NOT the correct way to specify rabbit is a subclass of animal?
    1. rabbit.__proto__ = animal
    2. let animal = { __proto__: rabbit };
    3. Rabbit.prototype = animal;
    4. Rabbit extends Animal
  6. Which of the following is NOT a valid way to create an object?
    1. let user = new Object();
    2. let user = new function() {...};
    3. let user = new function User() {...};
    4. let user = new User() {...};
  7. The key word "this" in a method of a class refers to which of the following ?
    1. The object that the method is called on.
    2. The object that the method is defined on.
    3. The object that the method is defined on, if it is a method of a class.
    4. The object that the method is called on, if it is a method of a class.
  8. The key word "override" refers to which of the following ?
    1. Overriding a method of supper class.
    2. Overriding a property of supper class.
    3. Overriding whole super class.
    4. Overriding parameters of a method.
  9. The key word "static" refers to which of the following ?
    1. Member can only be called by class 不能在类的实例上直接访问,而是通过类本身来访问
    2. Member can only be called by object
    3. Member can only be called by class and object
    4. Member can not be called by class or object
  10. If we need to know that whether an object is an instance of a class, which of the following is the correct way?
    1. object prototype of Class
    2. obj instanceof Class
    3. obj.__proto__ === Class.prototype
    4. obj.__proto__ === Class

True or False Question

  1. Class is a template of many objects. True
  2. Object is an instance of a class. True
  3. Class define the common properties and methods of many objects. True
  4. Object is abstraction of class. False
  5. In an arrow function, "this" refers to the object that the arrow function is called on. False
  6. Constructor is a special method that is used to create and initialize an object. True
  7. We use "new" keyword to create an object. True
  8. We can add methods into an object dynamically. True
  9. We can use "this" to access the property of an object. True
  10. JavaScript supports multiple inheritance.False 一个类不能继承多个类
  11. JavaScript supports overloading of methods. False
  12. Module is a way to organize code, in which we can group related variables and functions together. True

Definition of Term

  1. arrow function
  2. class
  3. object
  4. this
  5. override
  6. static
  7. constructor
  8. prototype
  9. inheritance
  10. encapsulation
  11. module
  12. chaining call

Short Answer

  1. What are the relationships between class and object?
  2. How many ways to create an object?
  3. How many ways to inherit from a class?
  4. How to encapsulate a class?

Programming

  1. Create an array with five student objects which has name and age properties, then write a function to calculate the average age of the students.
  2. Create a class to represent the shape, then create three subclasses: circle, triangle and square which can calculate the area.
  3. Create an object calculator with three methods: 1)read() prompts for two values and saves them as object properties. 2)sum() returns the sum of saved values. 3)mul() multiplies saved values and returns the result.
  4. 3)We have an object storing salaries of our team:
                    
                        let salaries = {
                          John: 100,
                          Ann: 160,
                          Pete: 130
                        }
                    
                
    Write the code to sum all salaries and store in the variable sum. Should be 390 in the example above. If salaries is empty, then the result must be 0.