Presentation is loading. Please wait.

Presentation is loading. Please wait.

Defining Your Own Classes Part 3. class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor)

Similar presentations


Presentation on theme: "Defining Your Own Classes Part 3. class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor)"— Presentation transcript:

1 Defining Your Own Classes Part 3

2 class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor) Methods (incl. Constructor)

3 Data Member Declaration ; private String ownerName ; Modifiers Data Type Name Note: There’s only one modifier in this example.

4 Method Declaration ( ){ } public void setOwnerName ( String name ) { ownerName = name; } Statements Modifier Return Type Method Name Parameter

5 Constructor is executed when a new instance of the class is created.A constructor is a special method that is executed when a new instance of the class is created. public ( ){ } public Bicycle ( ) { ownerName = "Unassigned"; } Statements Modifier Class Name Parameter

6 First Example: Using the Bicycle Class class BicycleRegistration { public static void main(String[] args) { Bicycle bike1, bike2; String owner1, owner2; bike1 = new Bicycle( ); //Create and assign values to bike1 bike1.setOwnerName("Adam Smith"); bike2 = new Bicycle( ); //Create and assign values to bike2 bike2.setOwnerName("Ben Jones"); owner1 = bike1.getOwnerName( ); //Output the information owner2 = bike2.getOwnerName( ); System.out.println(owner1 + " owns a bicycle."); System.out.println(owner2 + " also owns a bicycle."); }

7 The Definition of the Bicycle Class class Bicycle { // Data Member private String ownerName; //Constructor: Initialzes the data member public void Bicycle( ) { ownerName = "Unknown"; } //Returns the name of this bicycle's owner public String getOwnerName( ) { return ownerName; } //Assigns the name of this bicycle's owner public void setOwnerName(String name) { ownerName = name; }

8 Multiple Instances Once the Bicycle class is defined, we can create multiple instances. Bicycle bike1, bike2; bike1bike2 : Bicycle ownerName : Bicycle ownerName “Adam Smith” “Ben Jones” bike1 = new Bicycle( ); bike1.setOwnerName("Adam Smith"); bike2 = new Bicycle( ); bike2.setOwnerName("Ben Jones"); Sample Code

9 The Program Structure and Source Files BicycleRegistrationBicycle There are two source files. Each class definition is stored in a separate file. BicycleRegistration.javaBicycle.java To run the program: 1. javac Bicycle.java (compile) 2. javac BicycleRegistration.java (compile) 3. java BicycleRegistration (run)

10 Class Diagram for Bicycle Method Listing We list the name and the data type of an argument passed to the method. Method Listing We list the name and the data type of an argument passed to the method. Bicycle + setOwnerName(String) + Bicycle( ) + getOwnerName( ) - String ownerName public – plus symbol (+) private – minus symbol (-)

11 The Account Class class Account { private String ownerName; private double balance; public Account( ) { ownerName = "Unassigned"; balance = 0.0; } public void add(double amt) { balance = balance + amt; } public void deduct(double amt) { balance = balance - amt; } public double getCurrentBalance( ) { return balance; } public String getOwnerName( ) { return ownerName; } public void setInitialBalance (double bal) { balance = bal; } public void setOwnerName (String name) { ownerName = name; } Page 1Page 2

12 Second Example: Using Bicycle and Account class SecondMain { //This sample program uses both the Bicycle and Account classes public static void main(String[] args) { Bicycle bike; Account acct; String myName = "Jon Java"; bike = new Bicycle( ); bike.setOwnerName(myName); acct = new Account( ); acct.setOwnerName(myName); acct.setInitialBalance(250.00); acct.add(25.00); acct.deduct(50); //Output some information System.out.println(bike.getOwnerName() + " owns a bicycle and"); System.out.println("has $ " + acct.getCurrentBalance() + " left in the bank"); }

13 The Program Structure for SecondMain SecondMainBicycle SecondMain.javaBicycle.java To run the program: 1. javac Bicycle.java (compile) 2. javac Account.java (compile) 2. javac SecondMain.java (compile) 3. java SecondMain (run) Account.java Account Note: You only need to compile the class once. Recompile only when you made changes in the code.

14 Arguments and Parameters An argument is a value we pass to a method class Account {... public void add(double amt) { balance = balance + amt; }... } class Sample { public static void main(String[] arg) { Account acct = new Account();... acct.add(400);... }... } argument parameter A parameter is a placeholder in the called method to hold the value of the passed argument.

15 Matching Arguments and Parameters The number or arguments and the parameters must be the same class Demo { public void compute(int i, int j, double x) {... } Demo demo = new Demo( ); int i = 5; int k = 14; demo.compute(i, k, 20); 3 arguments 3 parameters The matched pair must be assignment- compatible (e.g. you cannot pass a double argument to a int parameter) Arguments and parameters are paired left to right Passing Side Receiving Side

16 Memory Allocation Separate memory space is allocated for the receiving method. Passing Side i5 k 14 20 Receiving Side i j x 5 14 20.0 Values of arguments are passed into memory allocated for parameters. Literal constant has no name

17 Information Hiding and Visibility Modifiers The modifiers public and private designate the accessibility of data members and methods. If a class component (data member or method) is declared private, client classes cannot access it. If a class component is declared public, client classes can access it. Internal details of a class are declared private and hidden from the clients. This is information hiding.

18 Accessibility Example class Service { public int memberOne; private int memberTwo; public void doOne() { … } private void doTwo() { … } … Service obj = new Service(); obj.memberOne = 10; obj.memberTwo = 20; obj.doOne(); obj.doTwo(); … ClientService

19 Data Members Should Be private they should be invisible to the clients. Declare them privateData members are the implementation details of the class, so they should be invisible to the clients. Declare them private. Exception: Constants can (should) be declared public if they are meant to be used directly by the outside methods.

20 Guideline for Visibility Modifiers Guidelines in determining the visibility of data members and methods: –Declare the class and instance variables private. –Declare the class and instance methods private if they are used only by the other methods in the same class. –Declare the class constants public if you want to make their values directly readable by the client programs. If the class constants are used for internal purposes only, then declare them private.

21 Diagram Notation for Visibility public – plus symbol (+) private – minus symbol (-)

22 Class Constants In Chapter 3, we introduced the use of constants. We illustrate the use of constants in programmer- defined service classes here. Remember, the use of constants –provides a meaningful description of what the values stand for. number = UNDEFINED; is more meaningful than number = -1; –provides easier program maintenance. We only need to change the value in the constant declaration instead of locating all occurrences of the same value in the program code

23 A Sample Use of Constants class Dice { private static final int MAX_NUMBER = 6; private static final int MIN_NUMBER = 1; private static final int NO_NUMBER = 0; private int number; public Dice( ) { number = NO_NUMBER; } //Rolls the dice public void roll( ) { ( number = (int) (Math.floor(Math.random() * )) (MAX_NUMBER - MIN_NUMBER + 1)) + MIN_NUMBER); } //Returns the number on this dice public int getNumber( ) { return number; }

24 Local Variables Local variables are declared within a method declaration and used for temporary services, such as storing intermediate computation results. public double convert(int num) { double result; result = Math.sqrt(num * num); return result; } local variable

25 Local, Parameter & Data Member An identifier appearing inside a method can be a local variable, a parameter, or a data member. The rules are –If there’s a matching local variable declaration or a parameter, then the identifier refers to the local variable or the parameter. –Otherwise, if there’s a matching data member declaration, then the identifier refers to the data member. –Otherwise, it is an error because there’s no matching declaration.

26 Sample Matching class MusicCD { private String artist; private String title; private String id; public MusicCD(String name1, String name2) { String ident; artist = name1; title = name2; ident = artist.substring(0,2) + "-" + title.substring(0,9); id = ident; }... }

27 Calling Methods of the Same Class So far, we have been calling a method of another class (object). It is possible to call method of a class from another method of the same class. –in this case, we simply refer to a method without dot notation

28 Changing Any Class to a Main Class Any class can be set to be a main class. All you have to do is to include the main method. class Bicycle { //definition of the class as shown before comes here //The main method that shows a sample //use of the Bicycle class public static void main(String[] args) { Bicycle myBike; myBike = new Bicycle( ); myBike.setOwnerName("Jon Java"); System.out.println(myBike.getOwnerName() + "owns a bicycle"); }

29  2005 Pearson Education, Inc. All rights reserved. 29 Methods: A Deeper Look

30  2005 Pearson Education, Inc. All rights reserved. 30 Object-oriented approach to modular design

31  2005 Pearson Education, Inc. All rights reserved. 31 Notes on Declaring and Using Methods Three ways to call a method: 1.Use a method name by itself to call another method of the same class double result = maximum( number1, number2, number3 ); 2- Use a variable containing a reference to an object, followed by a dot (. ) and the method name to call a method of the referenced object maximumFinder.determineMaximum(); 3- Use the class name and a dot (. ) to call a static method of a class ClassName. methodName ( arguments ) static methods cannot call non- static methods of the same class directly

32  2005 Pearson Education, Inc. All rights reserved. 32 Notes on Declaring and Using Methods (Cont.) Three ways to return control to the calling statement: – If method does not return a result: (void) Program flow reaches the method-ending right brace } or Program executes the statement return; – If method does return a result: Program executes the statement return expression ; – expression is first evaluated and then its value is returned to the caller

33  2005 Pearson Education, Inc. All rights reserved. 33 Declaring Methods with Multiple Parameters Multiple parameters can be declared by specifying a comma-separated list. numbertypesorder – Arguments passed in a method call must be consistent with the number, types and order of the parameters Sometimes called formal parameters class Demo { public void compute(int i, int j, double x) {... } Demo demo = new Demo( ); int i = 5; int k = 14; demo.compute(i, k, 20);

34  2005 Pearson Education, Inc. All rights reserved. The number or arguments and the parameters must be the same class Demo { public void compute(int i, int j, double x) {... } Demo demo = new Demo( ); int i = 5; int k = 14; demo.compute(i, k, 20); 3 arguments 3 parameters The matched pair must be assignment- compatible (e.g. you cannot pass a double argument to a int parameter) Arguments and parameters are paired left to right Passing Side Receiving Side

35  2005 Pearson Education, Inc. All rights reserved. 35 Outline MaximumFinder.java (1 of 2) Prompt the user to enter and read three double values Call method maximum Display maximum value

36  2005 Pearson Education, Inc. All rights reserved. 36 Outline Maximum Finder.java (2 of 2) Declare the maximum method Compare y and maximumValue Compare z and maximumValue Return the maximum value

37  2005 Pearson Education, Inc. All rights reserved. 37 Outline MaximumFinderTest.java Create a MaximumFinder object Call the determineMaximum method

38  2005 Pearson Education, Inc. All rights reserved. 38 Common Programming Error Declaring method parameters of the same type as float x, y is a syntax error instead of float x, float y -a type is required for each parameter in the parameter list.

39  2005 Pearson Education, Inc. All rights reserved. Call-by-Value Parameter Passing When a method is called, – the value of the argument is passed to the matching parameter, and – separate memory space is allocated to store this value. This way of passing the value of arguments is called a pass-by-value or call-by-value scheme. Since separate memory space is allocated for each parameter during the execution of the method, – the parameter is local to the method, and therefore – changes made to the parameter will not affect the value of the corresponding argument.

40 Call-by-Value Example class Tester { public void myMethod(int one, double two ) { one = 25; two = 35.4; } Tester tester; int x, y; tester = new Tester(); x = 10; y = 20; tester.myMethod(x, y); System.out.println(x + " " + y); produces 10 20

41 4 th Ed Chapter 7 - 41 Memory Allocation for Parameters

42 4 th Ed Chapter 7 - 42 Memory Allocation for Parameters (cont'd)

43  2005 Pearson Education, Inc. All rights reserved. Passing Objects to a Method As we can pass int and double values, we can also pass an object to a method. When we pass an object, we are actually passing the reference (name) of an object – it means a duplicate of an object is NOT created in the called method

44 Passing a Student Object class LibraryCard { private Student owner; public void setOwner(Student st) { owner = st; } LibraryCard card2; card2 = new LibraryCard(); card2.setOwner(student); Passing Side Receiving Side : LibraryCard owner borrowCnt 0 : Student name “Jon Java” email “jj@javauniv.edu” student card2 st 1 1 Argument is passed 1 2 2 Value is assigned to the data member 2 State of Memory

45  2005 Pearson Education, Inc. All rights reserved. Sharing an Object We pass the same Student object to card1 and card2 Since we are actually passing a reference to the same object, it results in owner of two LibraryCard objects pointing to the same Student object

46  2005 Pearson Education, Inc. All rights reserved. Returning an Object from a Method As we can return a primitive data value from a method, we can return an object from a method also. We return an object from a method, we are actually returning a reference (or an address) of an object. – This means we are not returning a copy of an object, but only the reference of this object

47  2005 Pearson Education, Inc. All rights reserved. Object-Returning Method Here's a sample method that returns an object: public Fraction simplify( ) { Fraction simp; int num = getNumberator(); int denom = getDenominator(); int gcd = gcd(num, denom); simp = new Fraction(num/gcd, denom/gcd); return simp; } Return type indicates the class of an object we're returning from the method. Return an instance of the Fraction class gcd method Return the Greatest Number Divisor

48 A Sample Call to simplify f1 = new Fraction(24, 36); f2 = f1.simplify(); public Fraction simplify( ) { int num = getNumerator(); int denom = getDenominator(); int gcd = gcd(num, denom); Fraction simp = new Fraction(num/gcd, denom/gcd); return simp; } f1 : Fraction numerator denominator 36 24 f2 simp : Fraction numerator denominator 3 2

49 4 th Ed Chapter 7 - 49 A Sample Call to simplify (cont'd) public Fraction simplify( ) { int num = getNumerator(); int denom = getDenominator(); int gcd = gcd(num, denom); Fraction simp = new Fraction(num/gcd, denom/gcd); return simp; } f1 = new Fraction(24, 26); : Fraction numerator denominator 3 2 f2 = f1.simplify(); f1 : Fraction numerator denominator 36 24 f2 simp : Fraction numerator denominator 3 2 The value of simp, which is a reference, is returned and assigned to f2.

50  2005 Pearson Education, Inc. All rights reserved. 50 Common Programming Error Confusing the + operator used for string concatenation with the + operator used for addition can lead to strange results. Java evaluates the operands of an operator from left to right. y has the value 5 For example, if integer variable y has the value 5, the expression "y + 2 = " + y + 2 results in the string "y + 2 = 52", not "y + 2 = 7", because first the value of y (5) is concatenated with the string "y + 2 = ", then the value 2 is concatenated with the new larger string "y + 2 = 5". The expression "y + 2 = " + (y + 2) produces the desired result "y + 2 = 7".

51  2005 Pearson Education, Inc. All rights reserved. 51 Common Programming Error Omitting the return-value-type in a method declaration is a syntax error. public maximum( double x, double y, double z ) double

52  2005 Pearson Education, Inc. All rights reserved. 52 Common Programming Error Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error. public double maximum( double x, double y, double z ) ; { public double maximum( double x, double y, double z )

53  2005 Pearson Education, Inc. All rights reserved. 53 Common Programming Error Redeclaring a method parameter as a local variable in the method’s body is a compilation error. public double maximum( double x, double y, double z ) { double y;

54  2005 Pearson Education, Inc. All rights reserved. 54 Common Programming Error Forgetting to return a value from a method that should return a value is a compilation error. void the method must contain return If a return value type other than void is specified, the method must contain a return statement that returns a value consistent with the method’s return- value-type. Returning a value from a method whose return type has been declared void is a compilation error.

55  2005 Pearson Education, Inc. All rights reserved. 55 Method Call Stack and Activation Records Stacks – Last-in, first-out (LIFO) data structures Items are pushed (inserted) onto the top Items are popped (removed) from the top Program execution stack – Also known as the method call stack – Return addresses of calling methods are pushed onto this stack when they call other methods and popped off when control returns to them

56  2005 Pearson Education, Inc. All rights reserved. 56 Method Call Stack and Activation Records (Cont.) – A method’s local variables are stored in a portion of this stack known as the method’s activation record or stack frame When the last variable referencing a certain object is popped off this stack, that object is no longer accessible by the program – Will eventually be deleted from memory during “garbage collection” Stack overflow occurs when the stack cannot allocate enough space for a method’s activation record

57  2005 Pearson Education, Inc. All rights reserved. 57 Argument Promotion and Casting Argument promotion – Java will promote a method call argument to match its corresponding method parameter according to the promotion rules – Values in an expression are promoted to the “highest” type in the expression (a temporary copy of the value is made) – Converting values to lower types results in a compilation error – Converting values to lower types results in a compilation error, unless the programmer explicitly forces the conversion to occur Place the desired data type in parentheses before the value – example: ( int ) 4.5

58  2005 Pearson Education, Inc. All rights reserved. 58 Fig. 6.5 | Promotions allowed for primitive types.

59  2005 Pearson Education, Inc. All rights reserved. 59 Common Programming Error Converting a primitive-type value to another primitive type may change the value if the new type is not a valid promotion.

60  2005 Pearson Education, Inc. All rights reserved. 60 Java API packages (a subset). (Part 1 of 2)

61  2005 Pearson Education, Inc. All rights reserved. 61 Java API packages (a subset). (Part 2 of 2)

62  2005 Pearson Education, Inc. All rights reserved. 62 Scope of Declarations Basic scope rules – Scope of a parameter declaration is the body of the method in which appears – Scope of a local-variable declaration is from the point of declaration to the end of that block – Scope of a local-variable declaration in the initialization section of a for header is the rest of the for header and the body of the for statement – Scope of a method or field of a class is the entire body of the class

63  2005 Pearson Education, Inc. All rights reserved. 63 Scope of Declarations (Cont.) Shadowing – A data member is shadowed (or hidden) if a local variable or parameter has the same name as the field This lasts until the local variable or parameter goes out of scope

64  2005 Pearson Education, Inc. All rights reserved. 64 Common Programming Error A compilation error occurs when a local variable is declared more than once in a method.

65  2005 Pearson Education, Inc. All rights reserved. 65 Error-Prevention Tip Use different names for data members and local variables to help prevent subtle logic errors that occur when a method is called and a local variable of the method shadows a field of the same name in the class.

66  2005 Pearson Education, Inc. All rights reserved. 66 Outline Scope.java (1 of 2) Shadows field x Display value of local variable x

67  2005 Pearson Education, Inc. All rights reserved. 67 Outline Scope.java (2 of 2) Shadows field x Display value of local variable x Display value of field x

68  2005 Pearson Education, Inc. All rights reserved. 68 Outline ScopeTest.java

69  2005 Pearson Education, Inc. All rights reserved. 69 static Methods, static Fields and Class Math static method (or class method) –Call a static method by using the method call: ClassName. methodName ( arguments ) –All methods of the Math class are static example: Math.sqrt( 900.0 )

70  2005 Pearson Education, Inc. All rights reserved. 70 Software Engineering Observation Class Math is part of the java.lang package, which is implicitly imported by the compiler, so it is not necessary to import class Math to use its methods.

71  2005 Pearson Education, Inc. All rights reserved. 71 static Methods, static Fields and Class Math (Cont.) Constants –Keyword final –Cannot be changed after initialization static fields (or class variables) –Are fields where one copy of the variable is shared among all objects of the class Math.PI and Math.E are final static fields of the Math class

72  2005 Pearson Education, Inc. All rights reserved. 72 Math class methods.

73  2005 Pearson Education, Inc. All rights reserved. 73 static Methods, static Fields and Class Math (Cont.) Method main –main is declared static so it can be invoked without creating an object of the class containing main –Any class can contain a main method The JVM invokes the main method belonging to the class specified by the first command- line argument to the java command

74  2005 Pearson Education, Inc. All rights reserved. 74 Reusing method Math.max Math.max( x, Math.max( y, z ) ) –The expression Math.max( x, Math.max( y, z ) ) determines the maximum of y and z, and then determines the maximum of x and that value String concatenation –Using the + operator with two String s concatenates them into a new String ident = artist.substring(0,2) + "-" + title.substring(0,9);Ex: ident = artist.substring(0,2) + "-" + title.substring(0,9); –Using the + operator with a String and a value of another data type concatenates the String with a String representation of the other value When the other value is an object, its toString method is called to generate its String representation

75  2005 Pearson Education, Inc. All rights reserved. 75 Method Overloading Method overloading – Multiple methods with the same name, but different types, number or order of parameters in their parameter lists – Compiler decides which method is being called by matching the method call’s argument list to one of the overloaded methods’ parameter lists name and number, type and order signatureA method’s name and number, type and order of its parameters form its signature – Differences in return type are irrelevant – Differences in return type are irrelevant in method overloading Overloaded methods can have different return types Methods with different return types but the same signature cause a compilation error

76  2005 Pearson Education, Inc. All rights reserved. Overloaded Methods Methods can share the same name as long as – they have a different number of parameters (Rule 1) or – their parameters are of different data types when the number of parameters is the same (Rule 2) public void myMethod(int x, int y) {... } public void myMethod(int x) {... } Rule 1 public void myMethod(double x) {... } public void myMethod(int x) {... } Rule 2

77  2005 Pearson Education, Inc. All rights reserved. 77 Outline MethodOverload.java Correctly calls the “ square of int ” method Correctly calls the “ square of double ” method Declaring the “ square of int ” method Declaring the “ square of double ” method

78  2005 Pearson Education, Inc. All rights reserved. 78 Outline MethodOverloadTest.java

79  2005 Pearson Education, Inc. All rights reserved. 79 Outline MethodOverload Error.java ERROR: Same method signature Compilation error

80  2005 Pearson Education, Inc. All rights reserved. 80 Common Programming Error Declaring overloaded methods with identical parameter lists is a compilation error regardless of whether the return types are different.

81  2005 Pearson Education, Inc. All rights reserved. Boolean Variables The result of a boolean expression is either true or false. These are the two values of data type boolean. We can declare a variable of data type boolean and assign a boolean value to it. boolean pass, done; pass = 70 < x; done = true; if (pass) { … } else { … }

82  2005 Pearson Education, Inc. All rights reserved. 4 th Ed Chapter 5 - 82 Boolean Methods A method that returns a boolean value, such as private boolean isValid(int value) { if (value < MAX_ALLOWED) return true; } else { return false; } Can be used as if (isValid(30)) { … } else { … }

83  2005 Pearson Education, Inc. All rights reserved. 4 th Ed Chapter 5 - 83 Comparing Objects With primitive data types, we have only one way to compare them, but with objects (reference data type), we have two ways to compare them. 1. We can test whether two variables point to the same object (use ==), or 2.We can test whether two distinct objects have the same contents.

84 4 th Ed Chapter 5 - 84 Using == With Objects (Sample 1) String str1 = new String("Java"); String str2 = new String("Java"); if (str1 == str2) { System.out.println("They are equal"); } else { System.out.println("They are not equal"); } They are not equal Not equal because str1 and str2 point to different String objects.

85 4 th Ed Chapter 5 - 85 Using == With Objects (Sample 2) String str1 = new String("Java"); String str2 = str1; if (str1 == str2) { System.out.println("They are equal"); } else { System.out.println("They are not equal"); } They are equal It's equal here because str1 and str2 point to the same object.

86 4 th Ed Chapter 5 - 86 Using equals with String String str1 = new String("Java"); String str2 = new String("Java"); if (str1.equals(str2)) { System.out.println("They are equal"); } else { System.out.println("They are not equal"); } They are equal It's equal here because str1 and str2 have the same sequence of characters.

87 4 th Ed Chapter 5 - 87 The Semantics of ==

88 4 th Ed Chapter 5 - 88 In Creating String Objects

89  2005 Pearson Education, Inc. All rights reserved. 89 Initializing Objects with Constructors Constructors – Initialize an object of a class – Java requires a constructor for every class – Java will provide a default no-argument constructor if none is provided – Called when keyword new is followed by the class name and parentheses

90 90 Outline GradeBook.java (1 of 2) Constructor to initialize courseName variable

91 91 Outline GradeBook.java (2 of 2)

92 92 Outline GradeBookTest.java Call constructor to create first grade book object Create second grade book object

93 93 Outline Account.java double variable balance

94 94 Outline AccountTest.java (1 of 3)

95 95 Outline AccountTest.jav a (2 of 3) Input a double value

96 96 Outline AccountTest.java (3 of 3) Output a double value Lines 14 - 17 Lines 23 - 25 Lines 30 - 33 Lines 35 - 38 Lines 42 - 45

97  2005 Pearson Education, Inc. All rights reserved. 97 UML class diagram indicating that class Account has a private balance attribute of UML type Double, a constructor (with a parameter of UML type Double ) and two public operations—credit (with an amount parameter of UML type Double ) and getBalance (returns UML type Double ).


Download ppt "Defining Your Own Classes Part 3. class { } Template for Class Definition Import Statements Class Comment Class Name Data Members Methods (incl. Constructor)"

Similar presentations


Ads by Google