What is the process of hiding object data and providing methods for data access called?

focusNode

Didn't know it?
click below

Knew it?
click below

Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

QuestionAnswer
What statement is used to specify the value that a method gives back to its caller? return
Which of the following declares a sideLength instance variable for a Square class that stores an integer value? private int sideLength;
What is the process of hiding object data and providing methods for data access called? encapsulation
A method header consists of which of the following parts? an access specifier, a return type, a method name, and a list of the parameters [if any]
Which of the following corresponds to a valid constructor header for the Player class? public Player[]
Which of the following is a valid constructor header for the Player class that accepts the player name as a parameter? public Player[String playerName]
Which of the following corresponds to the constructor header for a Square class that accepts an initial side length as an integer value? public Square[int initialLength]
Which of the following corresponds to the getArea method header for a Square class assuming an integer value for a side length? public int getArea[]
Which line of code is part of the private implementation of the BankAccount class? balance = balance - amount;
Which line of code is part of the public implementation of the BankAccount class? public BankAccount[double initialBalance]

  • True or False: To use encapsulation, you must provide a set of private methods in the class.

    False

  • True or False: Private instance variables hide the implementation of a class from the class user.

    True

  • What is wrong with this code?

    There is nothing wrong with this code.

  • True or False: An instance variable declaration consists of the type of the instance variable, an access specifier, and the name of the instance variable.

    False

  • True or False: To use encapsulation, you must provide a set of public methods in the class and hide the implementation details.

    True

  • Which of the following statements about objects is correct?

    b] Every object has its own set of data and a set of methods to manipulate the data.

  • True or False: The empName variable cannot be accessed at all because it is private.

    False

  • How many constructors are available in the code above?

    2

  • Which of the following are NOT considered part of the class’s public interface?

    rpmRating and designCode

  • The public constructors and methods of a class form the public _____________ of the class.

    a] interface

  • Name the accessor methods in the code segment above.

    getCoinName[] and getCoinValue[]

  • The process of hiding object data and providing methods for data access is called ____________.

    encapsulation

  • What is the correct order of items in an instance method declaration?

    modifiers, a return type, a method name, and a list of the parameters [if any]

  • True or False: setVehicleAttributes is a mutator method.

    True

  • What is the function of the constructor method in a class?

    A constructor initializes the instance variables of an object in a class.

  • Given class Counter, how many instances of the Counter class are created in the code segment?

    2

  • Given class Counter above, what output is generated by the code segment?

    2 1

  • Data required for an object's use are stored in _________________.

    instance variables

  • True or False: When a method that specifies a return type other than void is called and completes its task, the method must return a result to its calling method.

    True

  • A method in a class that modifies information about an object is called a/an ________________ method.

    mutator

  • Assuming that object birthday is an instance of the Date class, what is the correct way to call the getMonth[] method?

    birthday.getMonth[]

  • You should declare all instance variables as ____________________.

    private

  • The getMonth[] method in the code segment above can be considered an/a _______________ method. [accessor/mutator]

    accessor

  • The process of hiding object data and providing methods for data access is called ______________________.

    encapsulation

  • The ______________ keyword is used to construct an object from a class.

    new

  • True or False: Classes often provide public methods to allow the class’s clients to set or get private instance variables; the names of these methods must begin with set or get.

    False

  • Which of the following represents the final output of the code segment above?

    22

  • True or False: The argument types in the method call must be identical to the types of the corresponding parameters in the method’s declaration.

    True

  • True or False: The default value for an instance variable of type integer is 1.

    False

  • Consider the above code segment. Class Date contains ______ instance variables.

    3

  • True or False: The default value for an instance variable of type String is void.

    False

  • True or False: To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method’s arguments.

    False

  • Given the above class definition, which of the following are considered part of the class’s public interface?

    updatePrice and designCode

  • Write the line of code that declares a sideLength instance variable for a Square class that stores an integer value.

    private int sideLength;

  • A method in a class that returns information about an object but does not change the object is called a/an _________________ method.

    accessor

  • When an object is created from a class, the object is called a/an ________________ of the class.

    instance

  • Which term means the process of hiding object data and providing methods for data access?

    Encapsulation is a way to restrict the direct access to some components of an object, so users cannot access state values for all of the variables of a particular object. Encapsulation can be used to hide both data members and data functions or methods associated with an instantiated class or object.

    Which type of method modifies an object on which it operates?

    Mutator Method: This method is used to mutate/modify the state of an object i.e, it alters the hidden value of the data variable.

    What are the operations that any programmer can use to create and manipulate objects of the class called?

    Object Functions [or Methods] Once the data has been defined for what it means to be an object, then the programmer needs ways to manipulate that data. These ways are called functions. An object's functions have access not only to their parameters [as all functions do] but also to ALL Member Variable!

    What keyword statement is used to specify the value that a method gives back to its caller?

    A statement with the return keyword followed by a variable, constant, or expression that matches the return type will return that value to the method caller. Methods with a non-void return type are required to use the return keyword to return a value.

    Chủ Đề