Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Java General Java Declaring classes, variables, and methods Tutorial

Now let's look at ways we can modify classes, methods, and variables. There are two kinds of modifiers -- access modifiers and non-access modifiers. The access modifiers allow us to restrict access or provide more access to our code.

Tutorial Details:

Java Declaring classes, variables, and methods

Now let's look at ways we can modify classes, methods, and variables. There are two kinds of modifiers -- access modifiers and non-access modifiers. The access modifiers allow us to restrict access or provide more access to our code.

Class modifiers
The access modifiers available are public , private , and protected . However, a top-level class can have only public and default access levels. If no access modifier is specified, the class will have default access. Only classes within the same package can see a class with default access. When a class is declared as public, all the classes from other packages can access it.

Let's see the effect of some non-access modifiers on classes. The final keyword (see Java keywords and identifiers for more on keywords) does not allow the class to be extended. An abstract class cannot be instantiated, but can be extended by subclasses:

public final class Apple {..}
class GreenApple extends Apple {} // Not allowed, compile time error
Method and variable modifiers

All the access modifiers can be used for members of a class. The private members can only be accessed from inside the class. The protected members can only be accessed by classes in the same package or subclasses of the class. The public members can be accessed by any other class.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Java General Java Declaring classes, variables, and methods Tutorial

View Tutorial:
Java General Java Declaring classes, variables, and methods Tutorial

Related Tutorials:

Java Q&A - Java Still Open
Java Q&A - Java Still Open
 
Static class declarations
Static class declarations
 
Smart object-management saves the day - JavaWorld November 1999
Smart object-management saves the day - JavaWorld November 1999
 
Use Microsoft's Internet Information Server as a Java servlet engine - JavaWorld June 2000
Use Microsoft's Internet Information Server as a Java servlet engine - JavaWorld June 2000
 
Master Java with these introductory books - JavaWorld May 2001
Master Java with these introductory books - JavaWorld May 2001
 
Object-oriented language basics, Part 7
Object-oriented language basics, Part 7
 
Twelve rules for developing more secure Java code
Twelve rules for developing more secure Java code
 
JSP best practices
Follow these tips for reusable and easily maintainable JavaServer Pages
 
Call JavaBean methods from JSP
Call JavaBean methods from JSP 2.0 pages
 
Declarative Programming in Java
Declarative Programming in Java What makes EJB components special is the declarative programming model through which we can specify the services such as security, persistence, transaction etc., that the container should provide. An EJB only implements
 
Learn to speak Jamaican
Introducing Jamaica, a JVM macro assembler language Most Java programmers, at one time or another, have wondered how the JVM works. Java bytecode programming reveals much insight into the JVM and helps developers program Java better. Also, the ability t
 
Jython
Get to know Jython, in this first article in a new series introducing alternate languages for the Java Runtime Environment, alt.lang.jre. Jython is an implementation of the popular scripting language Python, but running on a JVM. For Python developers Jyt
 
Understanding the Interplay Between Utility Classes and Static Initialization
Java is an OO language, which means much of the functionality of a Java application is encapsulated into cohesive classes that can be instantiated and acted upon.
 
The Introduction to generic types in JDK 5.0
This tutorial introduces generic types, a new feature in JDK 5.0 that lets you define classes with abstract type parameters that you specify at instantiation time. Generics increase the type safety and maintainability of large programs. Follow along with
 
Java Beans, Part 1 Introducing Java Beans
The basic idea of the Beans tutorial is to get you to the point where you can quickly create beans. You may want to write new beans from scratch, or you may want to take existing components, applets, or other classes and turn them into beans.
 
Servlet Essentials
This document explains the concepts of Java Servlets and provides a step-by-step tutorial for writing HTTP Servlets with complete source code for the example Servlets. The tutorial and the other chapters cover all facets of Servlet programming from a ...
 
JavaServer Pages Technology - Documentation
Sun's tutorial for Java Server Pages that provide a good introduction to design web pages with JSP.
 
Generating an XML Document with JAXB
In this tutorial, JAXB is used to generate Java classes from an XML Schema. An example XML document shall be created from the Java classes.
 
Understanding Network Class Loaders Class loaders
One of the cornerstones of Java dynamics, determine when and how classes can be added to a running Java environment.
 
Core Java Interview Questions!
Core Java Interview Questions! Core Java Interview Questions Question: What is transient variable? Answer: Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.