Print This Article Post Comment Add To Favorites Email to Friends Ezine Ready

In Java How To Control The Members With In The Class To Access Outside

By: Infocampus Home | Computers-and-Technology


In java we use access modifiers to control the members(method and variables) with in the class.
In java there are two types of modifiers :
[1] Access modifiers
[2] Non †access modifiers
Access modifiers specifies the accessibility or scope of a data member(non static global variable),method,constructor or class.
Access modifiers are of four types:
1.default
2.private
3.public
4.protected
There are many non-access modifiers such as static, abstract, synchronized, native, volatile, transient etc. Here, we will learn access modifiers
The four access levels are â'
-Visible to the package, the default. No modifiers are needed
-Visible to the class only (private).
-Visible to the world (public) java/j2ee classes bangalore
-Visible to the package and all subclasses (protected).
Default Access Modifier - No Keyword
Default access modifier means we do not explicitly declare an access modifier for a class, field, method, etc.For default access modifiers we don’t use any keyword .
A variable or method declared without any access control modifier is available to any other class in the same package. The fields in an interface are implicitly public static final and the methods in an interface are by default public.
Private Access Modifier - Private
Methods, variables, and constructors that are declared private can only be accessed within java course in bangalore the declared class itself.
Private access modifier is the most restrictive access level. Class and interfaces cannot be private.Variables that are declared private can be accessed outside the class, if public getter methods are present in the class.We can access outside the class using setters method
Using the private modifier is the main way that an object encapsulates itself and hides data from the outside world.
Public Access Modifier - Public
A class, method, constructor, interface, etc. declared public can be accessed from any other class. Therefore, fields, methods, blocks declared inside a public class can be accessed from any class belonging java training center bangalore to the Java Universe.
However, if the public class we are trying to access is in a different package, then the public class still needs to be imported. Because of class inheritance, all public methods and variables of a class are inherited by its subclasses.
The main() method of an application has to be public. Otherwise, it could not be called by a Java interpreter (such as java) to run the class.
Protected Access Modifier - Protected
Variables, methods, and constructors, which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class. Advance java training in bangalore
Protected access gives the subclass a chance to use the helper method or variable, while preventing a nonrelated class from trying to use it.
Why we use the main method as public?
The reason behind that JVM (Java Virtual Machine)look for the main method. JVM is library and program class is different ,if main() method is not public ,it willn’t be visible to the JVM and JVM willn’t get the main() and through the error as main() method not found.To avoid this we use main method as public.
Why we can’t take the class as private?
We can’t take the class as private because if class is best core java training in bangalore declared as private classloader will be unable to load the class memmbers into the memory(heap memory).

This is the basic about the access modifiers . To learn more interesting topics on java join Infocampus Software training Institute for java course and get 100% job assistance .




Article Source: http://www.eArticlesOnline.com

About the Author:
Infocampus provides java/j2ee classes bangalore with the live project. Attend 4 days free demo classes in java training center bangalore . Training is given by 10+ years experienced trainers on java course.Complete practical session is available .Learn OOPs concept,packages,servlet,hibernate etc. in java course .It provides real time project after the completion of java training
Infocampus provides best core java training in bangalore with the 100% placement assistance.Learn Core & Advance Java in the easiest way.
Contact at : 9738001024 or for more details on Advance java training visit at:http://www.infocampus.co.in/java-training-bangalore.html

Tags: , , , ,

Please Rate this Article

 

Not yet Rated

Click the XML Icon Above to Receive Computers-and-Technology Articles Via RSS!

Recent Related Articles From Computers-and-Technology

  • Hibernate A Framework For Mapping In Java
    By: Infocampus | Apr 28th 2017
    Hibernate is an object-relational mapping (ORM) library for Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database. Read

  • Software Development Services
    By: abigaylemark1 | Apr 27th 2017
    Companies, professional and individuals often require custom software applications to run their operations smoothly. Some are reticent to hiring a team of professionals for the task, thinking they don’t need it so much, but there are many benefits that come from personalized software development. It all depends on the com ... Read

  • Why Invest In Modded Controllers Xbox One
    By: abigaylemark1 | Apr 27th 2017
    If you are used to playing online games and not using anything that might help you become better at it, you should know that you have been missing out on a long list of advantages that are usually associated with modded controllers xbox one. The same goes if you check out modded controllers ps4 and do not really know whethe ... Read

  • Where Can You Find Mod Controllers Ps4?
    By: abigaylemark1 | Apr 27th 2017
    Even though you might believe that you can come across mod controllers xbox one in gaming stores that can be found in your area, you should know that this would be impossible seeing as these products are usually hard to get by. At the same time, you might want to know that mod controllers ps4 that actually work and offer yo ... Read

  • Which Smartphone For Which Purpose?
    By: Antoine | Apr 27th 2017
    Nowadays there are many Smartphone brands and more than a thousand of different mobile are available on the market. In this universe of electronic devices, it is easy to get lost when you want to buy a Smartphone. Which one is the best for you? What kind of phone should you choose which is the most adapted to your need and ... Read

  • How Does The Digital Egt Gauge Actually Works?
    By: Joseph Polizzotto | Apr 27th 2017
    EGT gauges are found in specific autos and planes. By observing EGT, the driver or pilot can get a thought of the vehicle's air-fuel proportion. Read

  • In Java How Collection Is Single Unit Of Objects
    By: Infocampus | Apr 26th 2017
    A collections framework is a unified architecture for representing
    and manipulating collections. Collection represents a single unit of objects i.e. a group.
    Read

  • Packages A Mechanism Which Makes The Code Easy In Java
    By: Infocampus | Apr 25th 2017
    A java packages is a collection of comparative sorts of classes, interfaces and sub-packages. Packages in java can be arranged in two forms: built-in packages and user defined packages. Read

  • Gmail Help & Support Gmail Technical Support Number: 1-888-996-3777
    By: JASTINE | Apr 24th 2017
    gmail password Forget
    How To Reset Gmail Password
    Gmail Hijacked
    How To Set up a Gmail Account in cell phone
    How To Set up a Gmail On IPhone
    How To Restore Gmail Contacts
    How To Change Gmail Password
    How To Recover Gmail Password
    Forget Gmail Recovery Option
    Gmail Troubl ...
    Read

  • Exception Handling A Concept To Avoid The Program Terminate Improperly In Java
    By: Infocampus | Apr 22nd 2017
    When java executing any faulty statement , an interruption occur or program terminated improperly .that is known as exception.We need to handle the exception using exception handling mechanism. Read


Copyright © 2005-2015 eArticlesOnline, LLC - All Rights Reserved
Terms of Service | Privacy Policy