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

  • Federal Cyber Security And Mobility In Execution
    By: Megan Darcy | Jun 26th 2017
    As the Federal Government is growing bigger and bigger, the proneness to cyber attack of its agency systems are growing geometrically. Read

  • Check Out The Guide To Pdf Emailing Software Tool
    By: Jeremy Brown | Jun 22nd 2017
    Printing invoices, sorting them and mailing them †isn’t it a boring job, taking off too much time from productivity? Read

  • Social Media And Business
    By: HiCinko | Jun 20th 2017
    In today’s world, as we can see that technology is rising at a very rapid pace and has certainly taken hold of everyone and everything in the society in a fairly strong manner. And as we can see around ourselves, and for that we don’t need any kind of surveys or any kind of statistics, that how social media has been an ... Read

  • Benefits Of Buying Ipad Repair Parts From Wholesale Seller In Online
    By: JESSICA SMITH | Jun 16th 2017
    This article is about all cell phone repair parts.This article will tell you the benefits of buying repair parts of mobile phone instead of buy new cell phone.If you will read once , you will feel good and your thinking will be change definitely. Read

  • Cognos Online Training
    By: Leotrainings | Jun 16th 2017
    LEO trainings is best in the region in which u can change your future in your splendid profession with our SAP MM online training in Hyderabad. After of total of the way you transform into the pleasantly confirmed master inside the commercial center. Read

  • Mongodb Training In Marathahalli Bangalore
    By: First Enquiry | Jun 15th 2017
    MongoDB is a free and open-source cross-platform, report situated database that gives, elite, high accessibility, and simple adaptability. MongoDB chips away at idea of accumulation and report. Read

  • Basic Principles Of Non-destructive Testing
    By: pitekmnd | Jun 13th 2017
    NDTCS offers NDT Schools Training Center-Houston together with the internet based Online NDT Testing training,
    NDT certification, NDT auditing & NDT inspection and NDT Level III Consulting services in the field of Nondestructive Testing.
    Read

  • Why The Vital Role Of Sensors In An Aircraft Engine Monitoring And Control
    By: Joseph Polizzotto | Jun 13th 2017
    These sensors and accessories do not work alone. Through real-time monitoring and reconfiguration, air-traffic control is able to monitor the control and health of the vehicle. Read

  • Monitor Your Target’s Mobile App Through Android 007
    By: romyfernandis | Jun 12th 2017
    Previously it was not easy to track someone, but now in this era of technology everything has become simple. Now you do not need to go to any detective agency to hire an agent for keeping an eye on your target. You can spy on anyone by your own without letting him/her know through your smart phone. Yes, smart phones have ma ... Read

  • Keep An Eye On Your People From Your Phone
    By: romyfernandis | Jun 12th 2017
    Now people can keep an eye on people whom they want to. They do not need to send any detective to follow them and track their activity. Android 007 is the application which can help you in tracking the activities and location of the person you want. Read


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