PackageCom.imooc;//1. Definition of a class Public classTelphone {//2. What are the attributes (member variables) floatScreen ; floatCPU; floatMem; intvar = 30; //3. How to do voidCall () {intvar = 40; intLocalvar=0; System.out.println ("var:" +var); System.out.println ("Loclavar:" +LocalVar); System.out.println ("var:" +var); System.out.println ("Telphone has the function of calling!" "); } voidSendMessage () {intLocalvar=0; System.out.println ("var:" +var); System.out.println ("Screen:" +screen+ "CPU:" +cpu+ "mem:" +mem+ "Telphone has the function of texting! "); }}
PackageCom.imooc; Public classInitialtelphone { Public Static voidMain (string[] args) {//TODO auto-generated Method StubTelphone phone =NewTelphone (); //Phone.sendmessage (); //Assigning a value to an instance variablePHONE.CPU = 1.4f; Phone.mem= 2.0f; Phone.screen= 5.0f; //methods for calling objects//phone.sendmessage ();Phone.call (); }}
member variables and local variables in Java