Download presentation
Presentation is loading. Please wait.
1
Intro To Classes Review
Chapter 5
2
Short Answer What happens to an object’s memory storage when it is no longer referenced by a variable? It is deleted in a process called Garbage Collection
3
Short Answer What is the difference between a class and an object? An object is a run-time entity that contains data and responds to messages. A class is a software package or template that describes the characteristics of similar objects
4
Short Answer For each one you get correct, you get one point. List the three important characteristics of an object. State, Behavior and Identity
5
Short Answer What are mutators? A mutator is a message that changes an object’s state.
6
Short Answer What are accessors? An accessor is a message that is used to access an object’s state.
7
Short Answer List two visibility modifiers The two visibility modifiers are public and private. Private is often used for instance variables and prevents clients from referring to the instance variables directly. Public is used to ensure that the class is accessible to all potential clients.
8
Short Answer What is a constructor method? A constructor initializes the instance variables of a newly instantiated object.
9
True or False Can two variables refer to the same object? True
10
Short Answer How does a default constructor differ from other constructors? Sets all values to 0 or null.
11
Short Answer Give an example of a primitive data type?
12
Short Answer Explain the difference between formal parameters and actual parameters. Parameters listed in a method’s definition are called formal parameters. Values passed to a method when it is invoked are called actual parameters.
13
Short Answer What is the purpose of local variables? Local variables are used when a variable is temporarily needed within a method.
14
Write the Code Define a method “sum”. This method expects two integers as parameters and returns the sum of the numbers ranging from the first integer to the second one. public int getSum(int i, int j){ int sum; sum = int i + int j; return sum; }
15
Write the Code Define a method “average”. This method expects three doubles as parameters and returns the average of the numbers. public int getAverage(double x, double y, double z){ double average; average = (x + y + z)/3.0; return average; }
16
Write the Code Define a method “setName”. This method expects one String as a parameter and sets it equal to the instance variable name. This method returns nothing. public void setName(String s){ name = s; }
17
Final Jeopardy Define a contructor for a student class. This constructor sets the name, four test scores and its id number. The name is a String, test scores are integers and the id number is a double. The instance variable are name, test 1, test2, test3, test4 and id.
18
Final Jeopardy public Student(String n, int t1, int t2, int t3, int t4, double idNum){ name = n ; test1 = t1; test2 =t2; test3 =t3; test4 = t4; id = idNum; }
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.