Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

please send code example of inner classes?

Answer Posted / amit singh

here is the code of inner classes in which you will get all
inner classes in a one code


//interface for anonymous class

interface Aishwarya
{
public static final int lm = 10;
void intmeth();
}



//class for cretaing anonymous class
class Amitabh
{

void isit()
{
System.out.println("in superclass Amitabh");
}

}



//outer class for the regular inner class
class Outer
{
private static int i;
static int j;
Outer()
{

}


Outer(int i,int j)
{

this.i = i;
this.j = j;

}



public int add()
{

return i+j;

}


private int substract()
{
return (j-i);
}



public static void show2()
{
System.out.println("inner show in static method");
Outer.Inner j = new Outer().new Inner();
j.show();
}


public void show1()
{
Inner f = new Inner();
f.show();
}


//just to define how argument define anonymous class work
public void argument(Aishwarya a1)
{
Aishwarya a2 = a1;
System.out.println("value of interface constant " + a2.lm);
a2.intmeth();
}



//simple regular inner class
class Inner
{

public void show()
{
System.out.println("show add in inner" + add());
System.out.println("show substarct in inner" + substract
());
System.out.println("value of i of outer" + i);
System.out.println("value of j of outer" + j);
System.out.println("value of i of outer through this" +
Outer.this.i);
System.out.println("value of j of oter through this" +
Outer.this.j);

}
}

//end of the inner class




//static nested class is not real inner class
static class Bye
{
void statmeth()
{
System.out.println("hi im static only acess the statis var
method of outer class");
System.out.println("don't need for me to create the outer
instance");
System.out.println("because i'm Outerclass type");
System.out.println("value of i from outer which is
static :" + i);

//don't do it

//System.out.println("value " + add());
}
}//end of static class





//anonymous class
Amitabh a = new Amitabh(){
public void isit()
{
System.out.println("isit
abs bay borned in this");

}
public void isntpoosible()
{
System.out.println("isnot
in superclass");
}


};




public void did()
{
a.isit();
//a.isntpoosible();
}


//main method of outer
public static void main(String []args)
{

Outer o1 = new Outer(4,5);
o1.did();

//here is how to define anonymous class in argument

o1.argument(new Aishwarya(){
public void intmeth()
{
System.out.println("hi
this is interface method implement");
}


});

System.out.println("in main " + o1.add());
System.out.println("substract in main" + o1.substract());
Outer.Inner i1 = new Outer().new Inner();
System.out.println("show in main");
i1.show();



// create the object of amit
Amit a112 = new Amit();
a112.hi();
a112.dosome();

//create the object of static class
Bye bbb = new Bye();
bbb.statmeth();
}
}
// end of outer






//just for manupulating the code
class Amit
{

public int j = 45;
public static int l = 10;
private String s1 = "amit";
public String s2 = "sumit";



public static void hi()
{

System.out.println("hi this is amit");
Outer.Inner j1 = new Outer().new Inner();

j1.show();

Outer o22 = new Outer();

System.out.println("outer add " + o22.add());
System.out.println("is there any requirement of method
local class so see it");
System.out.println("in static context you only able to
acess the static var from the enclose class");
System.out.println("don't get then do some differ");




//local method class in static method

class LocalInner1
{


public void seeall1()
{
System.out.println("print :" + l);
//System.out.println("string concat : " + s1+s2);
System.out.println("string concat :" + new Amit().s1 +
new Amit().s2);
//System.out.println("strig concat" + this.s1 + this.s2);


}


}
LocalInner1 i1 = new LocalInner1();
i1.seeall1();

}


public void dosome()
{

//String z = "i'm in mood to be access if you can";


final String z = "yes finallly access";
System.out.println("you only apply on mlc just abstract and
final if not get so do diifer ");
System.out.println("in Voidsome");


//local method inner class in instance method
class LocalInner2
{
public void seeall2()
{
System.out.println(j);
System.out.println("access the static :" + l);
System.out.println("acess private and public :" +
s1+s2+z);
}

}
LocalInner2 i2 = new LocalInner2();
i2.seeall2();

}
}




run this code you will get all aspect in this code in which
class what restricted what no .wvery inner classes you will
get in it
don't arg without run the code
thanks amit singh
amitsing2008@gmail.com
amit09mca

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data and its types?

1049


Name and explain the types of ways which are used to pass arguments in any function in java.

1126


Are arrays primitive data types?

1255


What is use of map in java?

1057


Can we have more than one package statement in source file ?

1091


What are classloaders?

1081


What is anagram word?

1052


What is the set interface in java programming?

1286


how to write a server program and sending the mails to the server using smtp protocol please help me

2113


What is string length in java?

999


Compare Mutex and Semaphore in java.

1051


What is primitive array?

943


What methods are used in Servlet?Applet communication?

2303


What is a nested structure?

1103


How do you find the independent variable?

1124