CSE 142 Lecture 24: Constructors & Encapsulation

69 views3 pages
Verified Note

Document Summary

1 // a client program of the point class written in lecture. 2 // this version uses the fully encapsulated and abstracted version. 5 // notice the use of the constructors and the "noun verb" syntax for calling. 6 // instance methods on the point objects. 8 public static void main(string[] args) { 9 point p1 = new point(5, 9); 10 point p2 = new point(-3, 3); 11 point p3 = new point(0, 0); 14 system. out. println( "point 1: " + p1); 16 system. out. println( "point 1 distance from origin: " + 17 system. out. println( "point 2 distance from origin: " + 19 system. out. println( "point 1 after translate: " + p1); 20 system. out. println( "point 1 distance from origin after translate: " + 1 // a class to represent a point on the x-y coordinate plane. 3 // this version is fully encapsulated and abstracted. 4 // private fields, the getter/setter methods, and the constructor.

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