Wednesday, June 3, 2015

Implicit - Explicit Parameters

Implicit Parameters :


// The object on which the methods are called are called IMPLICIT parameters
// The Datatype of the implicit parameters is the class in which the methods are defined


public class ImplicitParameters
{
public static void main(String[] args)
{
Names myData = new Names();
myData.myName = "Bpn";
myData.printMe(); // IMPLICIT parameters
}
}


class Names
{
String myName;
public void printMe()
{
System.out.println(myName);
}

}


Explicit Parameters :


// Any parameters that are supplied to the methods within its brackets becomes explicit parameters
// here int length =  Explicit parameters

public class ExplicitParameters
{
public static void main(String[] args)
{
MyData myData = new MyData();
int area = myData.getArea(20);
System.out.println(area);
}
}


class MyData
{
public int getArea(int length)  // EXPLICIT Parameters
{
return length * length;
}

}

No comments:

Post a Comment