Wednesday, 4 September 2019

Access Modifiers


Private

Only within the class
Default :
Accessible only within the package(out side of the package not accessible)
Protected :
Accessible within the package and outside of the package but through inheritance
Public :
Can be accessible everywhere( within the class,within the package,outside the package)







JDK, JRE & JVM

JDK
Java Development Kit (JRE & JVM)-used for developing java applications/Software’s
JRE
Java Run Time environment-used for run/install java application
JVM
Java virtual machine-responsible for executing java project

public static void main(String args[])-JVM search this syntax for executing the code


super keyword:

1.super can be used to refer immediate parent class instance variable.
2.super can be used to invoke immediate parent class method
3.super() can be used to invoke immediate parent class constructor.

final keyword

final -->variable, method and class
final int a=10; //the value of the variable is constant (we cannot change)
final void m1() // method we cannot override in the child class
final class Test //class cannot be extended
{
}

Call By Value and Call By Reference In Java

Example:

 CallByValAndCallByRef obj=new CallByValAndCallByRef();
        int x=10;
        int y=20;
        obj.sum(x,y); //Call by value or pass by value
      
        obj.p=100;
        obj.q=200;
        obj.swap(obj); //call by reference
        

             //After Swap
        System.out.println(obj.p);//200
        System.out.println(obj.q);//100
    }
  
    public int sum(int a,int b) {
        int sum;
        sum=a+b;
        return sum;
    }
  
    public void swap(CallByValAndCallByRef r)
    {
        int temp=r.p;
        r.p=r.q;
        r.q=temp;
    }

No comments:

Post a Comment