20/01/25 ----------- Q)What is the limitation of the previous application(AccountApplication.java)? =>Both the accounts have same state(data). =>Every object of a class will have same structure(properties) and behaviour.But for practical reasons, they should not have the same state. Q)How to ovecome the limitation of the above program? =>by making storeAccountData() method as parameterised method, this limitation can be overcome. void storeAccountData(int ano,String nm,float bal){ accno=ano; name=nm; balance=bal; }//instance method Note:- Every method has 2 parts. 1)method header 2)method body =>Task performing code written between the flower braces is nothing but the body of the method. =>Variables created in the method header are known as parameters. For eg. ano,nm, bal are parameters. =>Parameters are the means with which calling methods supply input data to the called methods. =>Method calling time supplied values are known as arguments. Q)Modify AccountApplication.java so as the two account objects have different state. class Account{ int accno; String name; float balance;//instance variables void storeAccountData(int ano,String nm,float bal){ accno=ano; name=nm; balance=bal; }//parameterised instance method void displayAccountData(){ System.out.println("ACCNO:"+accno); System.out.println("NAME:"+name); System.out.println("BALANCE:"+balance); }//non parameterised instance method }//Account data type created class AccountApplication{ public static void main(String args[]){ Account acc1=new Account(); acc1.storeAccountData(10001,"Rama",50000); System.out.println("First account details.........."); acc1.displayAccountData(); Account acc2=new Account(); acc2.storeAccountData(10002,"David",50000); System.out.println("Second account details.........."); acc2.displayAccountData(); } } Q)What is a constructor? =>A specialised method of a class whose name and the class name same and that doesn't have any return type not even void is known as a constructor. Q)What is the purpose of a constructor? =>Constructor is used to initialze an object.I.e. a constructor is used to give initial state to the object. Q)How are constructors classified? 1)zero argument/non parametersied/no argument/default constructor 2)parameterised constructor