pre4 - Solution to Prelab Exercises Chapter 4 1....

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution to Prelab Exercises Chapter 4 1. Constructors are special methods included in class definitions. a. What is a constructor used for? A constructor initializes an object when the object is instantiated. b. How do constructors differ from other methods in a class? The name of the constructor must be the same as the name of the class and a constructor has no return type. 2. Both methods and variables in a class are declared as either private or public . Describe the difference between private and public and indicate how a programmer decides which parts of a class should be private and which public. Public members of a class can be directly referenced from outside of the class but private members can be directly referenced only inside the class. Generally instance variables should be private to protect the variables from direct changes by programs using the class. All changes to the variables should be done by public methods provided by the class. Hence methods provided for client programs should be done by public methods provided by the class....
View Full Document

Page1 / 2

pre4 - Solution to Prelab Exercises Chapter 4 1....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online