chapter7_partii
DESCRIPTION
chapterTRANSCRIPT
Slide 1
UNIT- ICHAPTER IN BOOK- 7part- II-K. IndhuSYLLABUS COVERED HEREK. INDHUMethods:- Argument Passing into MethodsMethods Returning ObjectsIntroducing Access Specifier-public, privateUnderstanding staticUnderstanding finalGoalsK. INDHUMethods:- Argument Passing into MethodsMethods Returning ObjectsIntroducing Access Specifier- (i) public, (ii) privateUnderstanding-Static Variable,Static Method,Static BlockExample Programs for Static MembersUnderstanding-Final Class,Final Variable,Final Method.Argument passing- call by valueK. INDHU
Argument passing by referenceK. INDHU
K. INDHU
Method Returning objectsRecursion possible in javaK. INDHU
Introducing access specifiersK. INDHU
Introducing access specifiersK. INDHU
Understanding staticK. INDHUAt time we will want to define a class member that will be used independently of any object of that class.
However, it is possible to create a member that can be accessed thru class without thru object.
To create such a member, precede its declaration with the keyword static.
We can declare both methods and variables to be static.
The most common example of a static member is main( ).
main( ) is declared as static because it must be called before any objects exist.Java static memberK. INDHUDEFINITION-> If you declare any variable/method with static modifier, it is known static variable/method.
EXAMPLE-> static String companyname; public void static main(String args[]){ }MEANING->(1) The static variable can be used to refer the common property of all objects (that is not unique for each object).
(2) Shared Single Memory is allocated to static variable / method, irrespective of how many objects are created.
(3) Static Variables/Methods can be accessed using Classname as- . .
ADVANTAGE-> STATIC VARIABLE SAVES MEMORY.Regarding Java static memberK. INDHUInstance variables declared as static are, essentially, global variables.
Instead, all instances of the class share the same static variable.
Methods declared as static have several restrictions:- They can only call other static methods. They must only access static data. They cannot refer to this or super in any way.Static member exampleK. INDHU
Static member anotherexampleK. INDHU
Regarding Java static memberK. INDHUWHY JAVA MAIN METHOD IS STATIC?
=> (1) Because object is not required to call static method.
=> (2) If it were non-static method, jvm create object first then call main() method.
=> (3) Creating object for main() will lead the problem of extra memory allocation.
Static blockK. INDHU
Understanding finalK. INDHUDeclaring a variable as "final" prevents its contents from being modified hence forth.
We must initialize a final variable when it is declared, itself.
Thus->If you make any variable as final, you cannot change the value of final variable(It will be constant).Final variable exampleK. INDHU
Understanding Final methodK. INDHU
Understanding Final classK. INDHU
Understanding finalK. INDHUBlank Final Variable is a final variable that is not initialized at the time of declaration.
A blank final variable can be initialized only in constructor.
Once the blank final variable is initialized in constructor, it can not be changed hence forth.
So far we studiedK. INDHUMethods:- Argument Passing into MethodsMethods Returning ObjectsIntroducing Access Specifier-public, privateUnderstanding staticUnderstanding finalHAPPY LEARNING!!!