Computer Science: Programming with a Purpose Week 9 Quiz Answer

Computer Science Programming with a Purpose Week 9 Quiz Answer

Computer Science: Programming with a Purpose Week 9 Quiz Answer


In this article i am gone to share Coursera Course Computer Science: Programming with a Purpose Week 9 | Creating Data Types Quiz Answer with you..


Creating Data Types



Question 1)
Of the following, which best describes a class in Java?
  • Defines data type values
  • Implements a data type
  • Implements a test client
  • Creates and initializes new objects
  • Implements operations on data type values


Question 2)
What does a constructor return?
  • An object
  • Nothing (no return value)
  • A reference to an object
  • Instance variable values
  • A method that creates an object



Question 3)
What does an instance variable refer to in an instance method?
  • A value in the scope of the method
  • A value in the scope of the method's client
  • A value in the scope of the constructor associated with the method
  • A value associated with the object that was used to invoke the method
  • An object that was created by the constructor associated with the method



Question 4)
A shadow in a Java data type implementation refers to which of the following?
  • Two constructors with the same name
  • An instance method with the same name as a constructor
  • A local variable with the same name as an instance variable
  • An instance variable with the same name as a constructor
  • An instance method with the same name as a static method



Question 5)
Suppose you want to add a constructor to Complex that takes a double value as its argument and creates a Complex number with that value as the real part (and imaginary part equal to 0). You write the following code:

public void Complex(double real) 
{
   re = real;
   im = 0.0; 
}

But then the statement Complex C = new Complex(1.0) does not compile. Why?

  • The types of re and im are not declared.
  • A class can only have one constructor.
  • Constructors do not have return types, not even void.
  • The return type should be complex, not void.
  • None of the above.







Post a Comment

0 Comments