40 likes | 126 Views
Various method signatures. View findViewById ( int id); Intent this.getIntent (); int getAction (); Editable getText (); String getStringExtra (String key); int [] getIntArrayExtra (String key); ArrayList <String> getStrings ( int param ); double getDouble (Sting param );
E N D
Various method signatures View findViewById(int id); Intent this.getIntent(); intgetAction(); Editable getText(); String getStringExtra(String key); int[] getIntArrayExtra(String key); ArrayList<String> getStrings(intparam); double getDouble(Sting param); String getString(); Int[][] getTwoDimIntArray(ArrayList<int> param); float getFloat(int param1, int param2); float[] getFloatArray(); void andYesSomeMethodsReturnNothing();
Classes and Constructors Class name <name> A class is a template from which objects are made Attribute 1 Attribute 2 <name>(params) <…> method1(<params>) <…> method2(<params>) Constructor always has the same name as the class (there can be more!) When the constructor is called, Java allocates space in memory for the attributes: Attribute1 (uninitialized) Attrubute2 (uninitialized) The system “knows” that this object is an instance of the class The constructor can initialize the attributes Attribute1 (initialized) Attrubute2 (initialized)
Classes and Constructors (2) MyClass So suppose our class in named MyClass Then an instance of the class is created by the statement in which the constructor is invoked: MyClassmyClass = new MyClass(3,4) int width intheigth MyClass(intw,int h) int area() When the constructor is called : MyClassmyClass = new MyClass(3,4) width (uninitialized) height (uninitialized) When the constructor is executed: 3 4 When the method area is called on the object myClass: int area = myClass.area(); the method area is called for the object that has width 4 and height 3 Within the methods, this always refers to the object on which the method is called, e.g. this.width = w; sets the width of the myClass object to 3