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...


explain Anonynous inner class?

Answers were Sorted based on User's Feedback



explain Anonynous inner class?..

Answer / malligontla

You can also declare an inner class within the body of a
method without naming it. These classes are known as
anonymous inner classes.

Is This Answer Correct ?    25 Yes 2 No

explain Anonynous inner class?..

Answer / arjun

It is a class without any name. It is used when we want to
have an encapsulation(i.e. want to use an object of a class)
only once and never required again. we combine the object
creation and class code in a interesting way.

Is This Answer Correct ?    5 Yes 1 No

explain Anonynous inner class?..

Answer / javac

Anonymous inner class is a class inside a class with out
name.and it is always used create the object of itself and
store it into super class reference variable or Interface
reference variable.

Is This Answer Correct ?    3 Yes 0 No

explain Anonynous inner class?..

Answer / shaik baji

Anonymous inner class comes in two forms

1)Normal Anonymous Inner Class
2)Parametrized Anonymous Inner Class

1) Normal Anonymous Inner Class:

Again the Normal Anonymous Inner class is two types

a)Extending the class by Anonymous Inner Class
b)Implementing the interface by Anonymous Inner
Class

a)Extending the class by Anonymous Inner Class

class One
{
void printOne()
{
System.out.println("One");
}
}
class AnonymousDemoByClass
{
public static void main(String Arg[])
{
One obj = new One(){
void printOne()
{
printTwo();
}
void printTwo()
{
System.out.println
("Two");
}
};
obj.printOne();
}
}



Output: Two







b) Implementing the interface by Anonymous Inner
Class

interface One
{
void printOne();
}
class AnonymousDemoByInterface
{
public static void main(String Arg[])
{
One obj = new One(){
public void printOne()
{
printTwo();
}
void printTwo()
{
System.out.println
("Two");
}
};
obj.printOne();
}
}

Output: Two

2)Parametrized Anonymous Inner Class:

Here we are implementing our Anonymous inner class as a
paramer to any method.

interface One
{
void printOne();
}

class ParameterizedAnonymousDemo
{
public static void main(String Arg[])
{
ParameterizedAnonymousDemo obj =
new ParameterizedAnonymousDemo();
obj.doSomething(new One(){
public void printOne
()
{

System.out.println("One");
}
});

}
public void doSomething(One objOne)
{
objOne.printOne();
}
}

Is This Answer Correct ?    3 Yes 0 No

explain Anonynous inner class?..

Answer / guest

Anonymous class is a class that doesnot have a name.

Is This Answer Correct ?    3 Yes 0 No

explain Anonynous inner class?..

Answer / preetesh

An Anonymous class is an inner class that is not assigned a
name. It is defined and instantiated within arguments of a
method of the Outer Class.

Syntax is as follows:
----------------------
public class OuterClass
{
//some relevant code

methodName(new ClassName(){ }); /*It indicates compiler
that the code between the braces in the argument of the
method defines an anonymours inner class.*/
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More Core Java Interview Questions

How do you use wildcards?

0 Answers  


Where pragma is used?

0 Answers  


Is call by reference possible in java?

0 Answers  


What does this mean java?

0 Answers  


What is meant by wrapper classes?

3 Answers  


What is a boolean structure?

0 Answers  


class A { public void disp(int a,int b) { System.out.println("hai"); } } class B { public void disp(int a,int b,int c) { System.out.println("hai"); } } above program is overloading or overriding?

9 Answers   Infosys, Wipro,


How we create object in copy constructor?

0 Answers   HCL,


What do you mean by ordered and sorted in collections in java?

0 Answers  


What is an class?

0 Answers  


Write java code to print "Hello how are you" Thread1 should have "Hello" Thread2 should have "how are you" both the threads should start at the same time

4 Answers   Huawei,


what is main purpose of abstract class?

7 Answers  


Categories