Share on Google+Share on Google+

Using Protected Access in JSP

In java there are three types of access specifiers: public, protected, private.

Using Protected Access in JSP


In java there are three types of access specifiers: public, protected, private. We always declare access specifiers to be more accessible. That means we have declared anything as a private, then we can make it either protected or public but not the other way round. The public specifier is accessible by anyone, the protected specifier can be accessed within the package only.

In this example we have created a jsp page. Inside the jsp page we have used the declaration tag. Inside this declaration tag we have made a reference of JspWriter class. JspWriter class is inside the javax.servlet.jsp package. We have defined a class Monitor inside which we have declared a method as protected.  Now make another class computer which extends Monitor, inside which we have declared one method getCPU(). Now close the declaration tag. To process the business logic now use the scriptlet directive. Inside this directive assigned the out implicit object to localOut object. Create a object of computer class. Now by the use of the reference of the object call the methods of a computer class and a Monitor class.  

The code of the program is given below:


        <TITLE>Using Protected Access in Jsp</TITLE>
        <H1>Using Protected Access in Jsp</H1>
            javax.servlet.jsp.JspWriter localOut;
            class Monitor
                protected void getMonitor()  throws
            class computer extends Monitor
                public void getCPU() throws 
            localOut = out;     
            out.println("Creating an computer...<BR>");
            computer a = new computer();

Output of the Program:

this example.


Posted on: February 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Using Protected Access in JSP  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image