Java Reference
In-Depth Information
Exercise 1.27 Create three students with the following details:
Snow White , student ID: A00234 , credits: 24
Lisa Simpson, student ID: C22044, credits: 56
Charlie Brown , student ID: A12003 , credits: 6
Then enter all three into a lab and print a list to the screen.
Exercise 1.28 Use the inspector on a LabClass object to discover what fields it has.
Exercise 1.29 Set the instructor, room, and time for a lab, and print the list to the terminal
window to check that these new details appear.
1.15
Summary
In this chapter, we have explored the basics of classes and objects. We have discussed the
fact that objects are specified by classes. Classes represent the general concept of things,
while objects represent concrete instances of a class. We can have many objects of any class.
Objects have methods that we use to communicate with them. We can use a method to make a
change to the object or to get information from the object. Methods can have parameters, and
parameters have types. Methods have return types, which specify what type of data they return.
If the return type is void , they do not return anything.
Objects store data in fields (which also have types). All the data values of an object together are
referred to as the object's state.
Objects are created from class definitions that have been written in a particular programming lan-
guage. Much of programming in Java is about learning to write class definitions. A large Java pro-
gram will have many classes, each with many methods that call each other in many different ways.
To learn to develop Java programs, we need to learn how to write class definitions, including fields
and methods, and how to put these classes together well. The rest of this topic deals with these issues.
Terms introduced in this chapter
object, class, instance, method, signature, parameter, type, state, source code,
return value, compiler
Concept summary
object Java objects model objects from a problem domain.
class Objects are created from classes. The class describes the kind of object; the objects
represent individual instantiations of the class.
 
 
Search WWH ::




Custom Search