How To Implement Protected Class In Java
Rate this article
0 out of 5
In this tutorial we will show you how to implement protected class in java. After viewing the video tutorial, download the source code and try to modify the code so as to get a feel of what is learned in this video tutorial.

 
Source Code

protected class.java

//program to illustrate the use of protected class in java

import java.io.*;
//declaring the base class

class Base
{
int roll;
String name;
//making the class protected type
protected Base()
{
roll=1;
name="Anna";
}
void display()
{
System.out.println("RollNo :"+roll);
System.out.println("Name   :"+name);
}
}

//Another class inherits 'Base'

class Derived extends Base
{
int marks;
//declaring derived class constructor

Derived()
{
marks=200;
}
void show()
{
display();
System.out.println("Marks  :"+marks);
}
}

//multi level inheritance

class SecDerive extends Derived
{
String place;
//defining constructor

SecDerive()
{
place="Pala";
}
void disp()
{
show();
System.out.println("Place  :"+place);
}
}

//creating a new class

class ProtectedClass
{
public static void main(String args[])
{
//creating object to invoke the function
SecDerive s=new SecDerive();
s.disp();
}


Source Code

About The Author
TekTips Videos

Number Of articles Posted      : 27
Number Of Messages Posted  : 0
Joined Date : 2013/2/04
   
Author
Messages
Posted:
Post Your Comments  
Name (Max 50 Chars)
Comments
 
 

 
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android