3, ఏప్రిల్ 2012, మంగళవారం

CONCEPT OF INNER CLASSES IN JAVA HERE ONE INTERESTING THING IS OUTER CLASS DATA IS ALLOWED TO ACCESS INNER CLASS BUT REVERSE WILL NOT HOLD


import java.lang.*;
import java.io.*;
class outer
{
private
int rno,i;
String  name;
int a[]=new int[5];
double per;
public void readdata()   throws Exception
{
DataInputStream k=new DataInputStream(System.in);
rno=Integer.parseInt(k.readLine());
name=k.readLine();
for(i=0;i<a.length;i++)
a[i]=Integer.parseInt(k.readLine());
}
public void calper()
{
inner i=new inner();
per=i.percentage();
}


public void printdata()
{
System.out.println("the rno of the student is "+rno);
System.out.println("the name of the student is"+name);
System.out.println("\n the total marks you entered are");
for(i=0;i<a.length;i++)
System.out.print("\t"+a[i]);
System.out.println("\nthe percentage obtained by the inner class is "+per);
}

private class inner
{
public double percentage()
{
double p,sum=0;
for(i=0;i<a.length;i++)
sum+=a[i];
p=(sum/5);
return p;
}
}
public static void main(String args[])   throws Exception
{
outer o=new outer();
o.readdata();
o.calper();
o.printdata();
}
}

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి