190 likes | 278 Views
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
E N D
COP3502: Introduction to CIS I Lecture 11
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> } }
anatomy of instance variables public class Complex { // instance variables //<modifiers> <type> <name>; publicdouble real; publicdoubleimag; ... … … }
anatomy of a constructor publicclass Complex { … … // constructor //<modifier> <class name> ( <arguments> ) publicComplex(intr, inti ) { real = r; imag = i; } … … }
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);
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; } … … }
packages collection of tools written by other programmers that perform specific operations
packages collection of tools written by other programmers that perform specific operations accessed using import keyword
packages collection of tools written by other programmers that perform specific operations accessed using import keyword import java.awt.Color;
Point p = new Point(3,4); OR Point p; p = new Point(3,4)
memory 1 byte = 8 bits
intnum; num 32 bits = 4 bytes
intnum; num = 400; binary - 110010000 num 32 bits = 4 bytes
Complex n; n = new Complex(3,4); n “reference”
Complex n1 = new Complex(8,6); Complex n2 = new Complex(3,5); n2 n1
Complex n; n = new Complex(8,6); “This is not a pipe” “n is not a Complex”