INB221 Lecture Notes - Lecture 4: Call Stack, Include Directive, Instance Variable

77 views4 pages

Document Summary

All programs we"ve used so far have used procedural style of programming we will now move on to defining classes and creating objects. We will be making a 2 dimensional point. If we were using a type, we"d create a struct with x and y coordinates in it, which can then be used as function results. The same functionality from a struct can be used by defining a point class. The main difference is that in a class you can declare public and private variables. If the point class is declared with public variables, you can create a new point class called pt" and then use pt. x" to get the x field inside the point class. This is considered bad practice though, as you want to declare variables as private, and then use methods inside the class to access the variables. E. g. creating a getx() method, which returns x, instead of using pt. x".

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents