1 / 19

Lecture 11

COP3502: Introduction to CIS I. Lecture 11. a natomy of a class. <modifier> class <class name> { // instance variables <modifiers> <type> <name>; // constructor <modifier> <class name> ( <arguments> ) { <constructor body> } // methods

tola
Download Presentation

Lecture 11

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COP3502: Introduction to CIS I Lecture 11

  2. anatomy of a class <modifier> class <class name> { // instance variables <modifiers> <type> <name>; // constructor <modifier> <class name> ( <arguments> ) { <constructor body> } // methods <modifiers> <return type> <function name> ( <arguments> ) { <function body> } }

  3. anatomy of instance variables public class Complex { // instance variables //<modifiers> <type> <name>; publicdouble real; publicdoubleimag; ... … … }

  4. anatomy of a constructor publicclass Complex { … … // constructor //<modifier> <class name> ( <arguments> ) publicComplex(intr, inti ) { real = r; imag = i; } … … }

  5. anatomy of a constructor public class Complex { … … // constructor //<modifier> <class name> ( <arguments> ) public Complex(intr, inti ) { real = r; imag = i; } … … } Complexcnum = new Complex(8,6);

  6. anatomy of a method public class Complex { … … // methods //<modifiers> <return type> <function name> ( <arguments> ) publicComplexadd(Complexn) { Complex sum = new Complex(real * n.real, imag * n.imag); return sum; } … … }

  7. packages collection of tools written by other programmers that perform specific operations

  8. packages collection of tools written by other programmers that perform specific operations accessed using import keyword

  9. packages collection of tools written by other programmers that perform specific operations accessed using import keyword import java.awt.Color;

  10. Point p = new Point(3,4); OR Point p; p = new Point(3,4)

  11. memory 1 byte = 8 bits

  12. intnum; num 32 bits = 4 bytes

  13. intnum; num = 400; binary - 110010000 num 32 bits = 4 bytes

  14. objects

  15. Complex n; n

  16. Complex n; n = new Complex(3,4); n “reference”

  17. Complex n1 = new Complex(8,6); Complex n2 = new Complex(3,5); n2 n1

  18. Complex n; n = new Complex(8,6); “This is not a pipe” “n is not a Complex”

  19. wrapper classes

More Related