How To Implement Private Class In Java
Rate this article
0 out of 5
In this tutorial we will show you how to implement private 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
private class.java

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

import java.io.*;

//declaring 'Base'class with member variables and functions

class Base
{
int roll;
String name;
private Base(int r,String n)
{
roll=r;
name=n;
}
void display()
{
System.out.println("RollNo  :"+roll);
System.out.println("Name    :"+name);
}
}

//Another class inherits 'Base' with its own member variables and functions

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

Derived(int r,String n,int m)
{
super(r,n);
marks=m;
}
void show()
{
display();
System.out.println("Marks  :"+marks);
}
}

//declaring a new class

class privateclassEx
{
//declaring the main class
public static void main(String args[])
{
Derived d=new Derived(1,"Anna",200);
d.show();
}
}



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