program to call value by method through constructor

package account_balamce;
public class Balance {
int bal; //bal and name initialised
String name;
Balance(int b, String n) //creating constructor for calling the paameter in two step 1st here and then adding 5 and sending to method showBalance
{
bal = b + 5;
name = n;
}
void showBalance()
{
System.out.println("NAME OF ACCOUNT HOLDER IS: " + name);
System.out.println("THE BALANCE OF ACCOUNT HOLDER IS : " + bal);
}
}

MAIN CLASS

package account_balamce;
public class Account_Balamce {
public static void main(String args[]) {
System.out.print("Details are: ");
Balance b = new Balance(50, "RAHUL KUMAR");
b.showBalance(); // if u do not want to use constructor add parameter here and it will be
}
}

No comments:

Post a Comment