set10 - Programming in Java 1 Java Classes Similar to C...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Programming in Java Programming in Java
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 2 Java Classes Java Classes Similar to C++ with minor differences:The Example: class Dog { . . . } Data member and functions
Image of page 2
Last modified: Jan. 2001 3 Data Members and Methods Data Members and Methods Data members ( fields) and member functions ( methods) are defined inside the class declaration. Instance variables and methods are associated with each instance of the class. Methods (functions) definitions are similar to C++.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 4 public class Point { private double x, y; public void setx(double value) { x = value; } public void sety(double value) { y = value; } } Data Members and Methods Data Members and Methods (continued) (continued) Example: instance variables instance methods
Image of page 4
Last modified: Jan. 2001 5 . . Point myPoint = new Point(); myPoint.setx(3.5); myPoint.sety(-7.0); Point anotherPoint = new Point(); anotherPoint.setx(125.0); anotherPoint.sety(15.0); . . Data Members and Methods Data Members and Methods (continued) (continued)
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001 6 Fields and Methods (continued) Fields and Methods (continued) null myPoint : x = 0.0 y = 0.0 * 3.5 y = -7.0 null anotherPoint : x = 0.0 y = 0.0 * x = 125.0 y = 15.0
Image of page 6
Last modified: Jan. 2001 7 Public class Point { private double x, y; private static int classID = 0; public void setx(double value) { x = value; } public void sety(double value) { y = value; } public static int classID() { return classID; } } Class Data Members and Methods Class Data Members and Methods Example: class variable class method
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Last modified: Jan. 2001
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern