Programming and Problem Solving with Java

(やまだぃちぅ) #1

370


18.Can an object file be written with a text editor? Explain.
19.Why does an object read from an object file have to be type cast back into its
original class?

Programming Warm-Up Exercises


1.Declare three constructors for the class MyClass.
2.Fill in the blanks in the documentation in the following code segment.
public classMyName extendsYourName
{
intmyField; // myField is an ______field.

publicMyName(intmyField) // _______ with a parameter
// that shadows the _______ ______
{
this.myField = myField; // Assign the ___________ to
// the _________ field.
}
}


  1. a.How does the syntax of a constructor differ from that of a method?
    b.How is a constructor invoked?
    c. How many constructors can a class have?
    d.What is the signature of a method?
    e.What happens if a class does not have a constructor?
    f. What must be the first statement in every constructor?

  2. a.Declare a publicclass SomeClass.
    b.Write the heading for a publicclass method someMethod.
    c. Write the heading for an integer class method someMethodthat should be ac-
    cessible to the classes in the package but not to derived classes.
    d.Write the heading for an integer class method someMethodthat should be ac-
    cessible only to other methods in the class.
    e.Write the heading for a character class method someMethodthat should be ac-
    cessible to classes in the package and any derived classes.

  3. a.Write the heading for a public method someMethod.
    b.Write the heading for an integer method someMethodthat should be accessi-
    ble to the classes in the package but not to derived classes.
    c. Write the heading for an integer method someMethodthat should be accessi-
    ble only to other methods in the class.


T


E


A


M


F


L


Y


Team-Fly®

Free download pdf