Trending ▼   ResFinder  

ICSE Class X Notes 2024 : Computer Applications

2 pages, 1 questions, 0 questions with responses, 0 total responses,    0    0
Computer Applications
  
+Fave Message
 Home > anivinutha >

Formatting page ...

Encapsulation Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. in encapsulation, the data in a class is hidden from other classes, so it is also known as datahiding. Benefits of Encapsulation The fields of a class can be made read-only or write-only. Other classes will not be able to access data directly because variables are private A class can have total control over what is stored in its fields and manipulations within class It improves flexibility and reusability. Scope The scope of a variable defines the section of the code in which the variable is visible. As a general rule, variables that are defined within a block are not accessible outside that block. The different types of variables are Instance variables Instance variables are those that are defined within a class itself and not in any method or constructor of the class. They are known as instance variables because every instance of the class (object) contains a copy of these variables. The scope of instance variables is determined by the access specifier that is applied to these variables. Class/Static Variables Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. There would only be one copy of each class variable per class, regardless of how many objects are created from it. Difference between Instance and Class variable Instance variable Class variable Each object will have its own copy of Only one copy of a static variable per class instance variable irrespective of how many objects we create. Changes made in an instance variable using one object will not be reflected in other objects as each object has its own copy of instance variable. We can access instance variables through object references Any changes made in static variable will be reflected in other objects as static variables are common to all object of a class. Static Variables can be accessed directly using without an object. Argument variables These are the variables that are defined in the header of constructor or a method. The scope of these variables is the method or constructor in which they are defined. The lifetime is limited to the time for which the method keeps executing. Once the method finishes execution, these variables are destroyed. Local variables A local variable is the one that is declared within a method or a constructor or in a block(not in the header). The scope and lifetime are limited to the method itself.

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2024 ResPaper. Terms of ServiceContact Us Advertise with us

 

anivinutha chat