There are three Access Modifiers:-
1.public
2.private
3.protected
and 4 Access controls:-
1.private
2.public
3.protected
4.default/friendly/no modifier
private:-Accessible with in only same class.
default:-this is the by default access of a variable or function.
default are accessible with in the same package.
protected:-accessible in same package or child class.
protected=default+child class
Child class may be in the same or different package.
Note:-We also need to import the package for using the public and protected members in another package.
Note:-class can be public or default. But can’t be private or protected.
Note:-In java only one class can be public and the name of class must be same otherwise you well get compile time error.
Array of Objects:-
First of create a array by writing
Complex[] c=new Complex[n];
n is the size of array of datatype Complex.
Now use a loop
for(int i=0;i<n;i++)
{
c[i]=new Complex();
}
This will create a array of objects.
Note:-we if skip c[i]=new Complex(); then we c[i] is referencing to null(by default). So we get null pointer exception.


No comments:
Post a Comment