Inner Class and Outer Class and array within class

With an object of outer class we cannot call the methods of inner class .

We cannot create an object of the inner class in main method but we can do so in any method of the outer class

Inner class can directly access outer class where as outer class cannot directly access inner class.

class out

{

int a=10;

void disp()

{

sysout(a);

inner a= new inner();

}

class inner

{

void disp()

{

sysout(“iinner”);

}

}

}

ARRAY WITHIN CLASSES

Class A

{

int a=0;

int []a=new int [5];

public void input()

for(i=0;i<5;i++)

{

a[i]=…(“enter series”);

}

public void output()

for(i=0;i<5;i++)

{

sop(a[i]);

}

}

Class main

{

public static void main(..)

{

A p=new A();

p.input();

p.output();

}

}

NESTING MEMBER FUNCTIONS

Class A

{

int a=0;

public void input()

for(i=0;i<5;i++)

{

a[i]=…(“enter series”);

}

private int large()

{

if(a>b)

return a;

else

return b;

}

public void output()

{

sop(large());

}

}

Class main

{

public static void main(..)

{

A p=new A();

p.input();

p.output();

}

}

OBJECT AS AN ARRAY

Class stu

{

int rno;

string name;

int age;

public void input()

{

sno=..;

name=..;

age=..;

}

public void output()

{

sop(+rno);

sop(+name);

sop(+age);

}

}

Class main

{

public static void main(..)

{

stu []st=new stu[5];

int i;

for(i=0;i<5;i++)

{

st[i]=new stu();

st[i].input();

st[i].output();

}

}

}

Advertisements

Constructive and genuine appreciation and/or criticism most welcome

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s