Professional Documents
Culture Documents
Chapter 12 Slides
Chapter 12 Slides
Chapter 12
Classes,
Collections, and
Inheritance
Creating a Class
where
• ClassName is name of class
• MemberDeclarations are declarations for all
variables, constants, and methods that belong to
class
myPerson.FirstName = txtFirstName.Text
myPerson.LastName = txtLastName.Text
Integer.Parse(txtAge.Text, myPerson.Age)
End Sub
End Class
sophomore.FirstName = "Travis"
sophomore.LastName = "Barnes"
Property procedure calls
sophomore.ID = "17H495"
sophomore.TestAverage = 94.7
aStudent = sophomore
End Sub
With this statement, 'sophomore' will not go out of scope.
Without this statement, it will go out of scope.
(aStudent is a class level variable)
Copyright © 2014 Pearson Education, Inc. 65
Comparing Objects
• When comparing objects
– Multiple variables may reference same object
– To determine if variables reference same
object
• Do NOT use equals (=) operator
• Use Is operator
– To determine if variables don't reference same
object
• Do NOT use not equals (<>) operator
• Use IsNot operator
End Sub
Return aStudent
End Function
Return aStudent
End Function
LastName = String.Empty
FirstName = String.Empty
Id = String.Empty
TestAverage = 0.0
End Sub
Collections
' Or
- or -
Dim myCustomer As Customer =
CType(customers(1), Customer)
students.Add(studentData)
– Example with key
Dim students As New Collection()
students.Add(studentData, studentData.Id)
Introduction to Inheritance
Return strMsg
End Function