PARAMETRIZED METHOD:
Method that is used to for passing information to a using parameters is called parametrized method for passing a information using method require two things first is type and second is variable name such as String n.Any type of data can be used as a parameter in in method such as integer,double and float.Array and object can also be used as a parameter as shown in below.
book(String n[]).
NOTE:One Should be kept in mind thatwe cannot use reserved keyword as a parameter name.
NOTE:One Should be kept in mind thatwe cannot use reserved keyword as a parameter name.
CODING:
class book{
String name,editor;
float prize;
int quantity;
void input(String n,String e,int q,float p)
{
name=n;
editor=e;
quantity=q;
prize=p;
}
void output()
{
System.out.println("Book Name= "+name);
System.out.println("Editor= "+editor);
System.out.println("Quantity= "+quantity);
System.out.println("Prize= "+prize+"$");
System.out.println();
}
}
class bookmain
{
public static void main(String arg[])
{
book information=new book();
information.input("Electronic Devices","Robert Boylestad",4,60);
information.output();
information.input("Electric Circuit","F.Bogart",10,35);
information.output();
information.input("Business","Ronald J.Ebert",2,15);
information.output();
}
}
No comments:
Post a Comment