Java Terminology - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Java Terminology - Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Thursday, March 14, 2019

Java Terminology

Java Terminology


üEach point is an object
üEach includes three fields
üEach has three methods
üEach is an instance of the same class


Object-Oriented Style

üSolve problems using objects: little bundles of data that know
 how to do things to themselves.
üNot the computer knows how to move the point, but rather the 
point knows how to move itself.
üObject-oriented languages make this way of thinking and 
programming easier.


class Point {


  int xCoord;

  int yCoord;

  Point() {

  xCoord = 0;

  yCoord = 0;

  }

  int currentX() {

  return xCoord;

  }

  int currentY() {

  return yCoord;

  }

  void move (int newXCoord, int newYCoord) {


 
xCoord = newXCoord;

  yCoord = newYCoord;

  }
}
The General Form of a Class

üA class is defined by specifying the data and the code that 
operate on the data.

üThe general form:

  class classname{

  type instance-variable1;

  type instance-variable2;
  …………

   type methodname1( parameter-list)

  {

  // body of the method

  }

  type methodname2( parameter-list)

  {

  //body of the method

  }
  ……………………
    }

No comments:

Post a Comment

Post Top Ad