DATA TYPES:
Any type of data can be used as a parameter in constructor such as integer,double and float.Array and object can also be used as a parameter as shown in below.
current( current[])
CODING:
class current{
double current;
double resistance;
//Creating Parameterize constructor
current (double c,double r)
{
current = c;
resistance = r;
}
double volt()
{
return current*resistance;
}
}
class voltage
{
public static void main(String args[])
{
//Creating Object Of current class
current cur=new current(10,40);
current cur1=new current(30,10);
System.out.println("Voltage is = "+cur.volt()+" volt");
System.out.println("Voltage is = "+cur1.volt()+" volt");
}
}
OUTPUT:
voltage is =400volt
0 comments:
Post a Comment