0% found this document useful (0 votes)
19 views2 pages

SEHH2242 Tutorial 02

Uploaded by

f5nrhsbkr9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

SEHH2242 Tutorial 02

Uploaded by

f5nrhsbkr9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SEHH2242 Tutorial 2 ((Classes and Objects – Part 1)

Task 1 (Revision Questions)

State whether each of the following is true or false. If false, explain why.

1. By convention, method names begin with an uppercase first letter and all
subsequent words in the name begin with a capital first letter.

2. Empty parentheses following a method name in a method declaration indicate that


the method does not require any parameters to perform its task.

3. Variables or methods declared with access modifier private are accessible only to
methods of the class in which they are declared.

4. Variables declared in the body of a particular method are known as instance


variables and can be used in all methods of the class.

5. Primitive-type local variables are initialized by default.

6. Reference-type instance variables are initialized by default to the value null.

7. Any class that contains public static void main( String args[] ) can be used
to execute an application.

8. The number of arguments in the method call must match the number of
parameters in the method declaration’s parameter list.

1
Task 2 (UML Class diagram)
With the following Java source code skeleton, draw the UML class diagram for
representing the class GradeBook:

// GradeBook.java
// GradeBook class with a constructor to initialize the course name.

public class GradeBook


{
private String courseName; // course name for this GradeBook
private String instructorName; // name of course's instructor

// constructor initializes courseName with String supplied as argument


public GradeBook( String course, String instructor )
{
// initializes courseName
// initializes instructorName
} // end constructor

// method to set the course name


public void setCourseName( String name )
{
// store the course name
} // end method setCourseName

// method to retrieve the course name


public String getCourseName()
{
return courseName;
} // end method getCourseName

// method to set the instructor name


public void setInstructorName( String name )
{
// store the course name
} // end method setInstructorName

// method to retrieve the instructor name


public String getInstructorName()
{
return instructorName;
} // end method getInstructorName

// display a welcome message to the GradeBook user


public void displayMessage()
{
// this statement calls getCourseName to get the
// name of the course this GradeBook represents
} // end method displayMessage

} // end class GradeBook

You might also like