, . , , , . .
- -, , , . .
- -, - , , , . , .
, , , ! , - . Java , .
() , private, protected, public. , . , .
private - ( ) . ! , private, .
- , , . , , !
, C++, .
protected - , , - ( ).
public - ( , ).
,
class Vis1 {
private int x=10,y=10;
int p1=1;
protected int p2=1;
public int p3=1;
}
x,y,p1,p2,p3. x y private, p1 , p2 protected, p3 public. , .
, . , . , , .
|
|
, ( ), , . , .
: , . , 1 n:
double sum1(int n){
int i;
double r=0;
for(i=1;i<=n;i++){
r+=i;
};
return r;
}
:
c=obj1.sum1(1000);
i r obj1.sum1(1000). , i r.
. : . , . (garbage collector). , - , , .
. :
- . .
- . {}, . .
- for. .
.
this ( C++), . , this . , x show(), this.x , x, this.show() , show(). , , , this. , this , . , , .
this ( static), .
, , . :
- ( ), . set. , , . ( ) , this. , x, x, :
|
|
void setX(double x){
this.x=x
}
- ( ), . . this.
- ( ), for - , {}, . Java . , this.
- (, ), for - , {}, . Java . , (is already defined).
- , , . Java , .