1. Give us an example of declaring and assigning values to a single-dimensional
ID: 3793783 • Letter: 1
Question
1. Give us an example of declaring and assigning values to a single-dimensional Array.
2. Give us an example of declaring and assignment values to a two-dimensional Array.
3. Object variables are complex in that they point to one or more data variables and they have methods (code) defined to act on the individual data of any one object of that Class type. Using Circle Class tell us how the author demonstrates the previous statement.
UML Class Diagram Circle Class name Data fields radius: double Circle C) Constructors and methods Circle (newRadi us double) getAreaC): double get Perimetero: double setRadius(newRadius: double): void circlel Circle drde2E Circle UML notation for objects radius 1 radius 25 radius 125 FIGURE 9.4 Classes and objects can be represented using UML notation. The method is denoted as methodName (parameterName: parameter Type) returnTypeExplanation / Answer
[1] 1-D array -->
[A] declare and assign value in different statement.
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
[B] Both in sinle statement.
int [] a = {10,20,70,40,50};
2. 2-D array -->
[A] declare and assign value in different statement.
int[][] arr=new int[3][3];//3 row and 3 column
arr[0][0]=1;
arr[0][1]=2;
arr[0][2]=3;
arr[1][0]=4;
arr[1][1]=5;
arr[1][2]=6;
arr[2][0]=7;
arr[2][1]=8;
arr[2][2]=9;
[B] Both in sinle statement.
int arr[][]={{1,2,3},{4,5,6},{7,8,9}};
[3]
Author demonstrates that for the each class object there is separte copy of each class memeber except static member.
In the given UML diagram Circle class having 3 Object and for each object instance variable (radius) having different value.When we call any method given in UML diagram , we have to use DOT operatror, which will identified the particuler object class memeber values.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.