Java - Interview Questions and Answers for 'Nested class' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Nested class' - 13 question(s) found - Order By Newest

 Q1. Which of the following can be marked static ?

a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes
Core Java
Anonymous
Ans. Methods , Variables , Initialization Blocks and nested Classes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q2. Difference between nested and inner classes ?
Anonymous
Ans. Inner classes are non static nested classes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   static   nested classes   inner classes   basic interview question      basic        frequent

Try 1 Question(s) Test


 Q3. What is a nested interface ?
Anonymous
Ans. Any interface declared inside a class or an interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   nested classes


 Q4. Which of the following cannot be marked static ?

a. Constructors , Classes ( Outer ) , Classes ( nested ), Interfaces , Local variables , Inner Class methods and instance variables.
b. Constructors , Classes ( Outer ) , Interfaces , Local variables , Class variables , Class Methods , Inner Class methods and instance variables.
c. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.
d. Constructors , Classes ( Outer ) , Classes (Nested), Interfaces , Local variables , Inner Class methods and instance variables
Anonymous
Ans. Constructors , Classes ( Outer ) , Interfaces , Local variables , Inner Class methods and instance variables.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q5. Explain use of nested or inner classes ?
Anonymous
Ans. Sometime we just need classes or class objects just to be used as part of a particular class or objects. Making them non nested won't make any difference as far as functionality is concerner but making them Nested provide a level of convenience and protection fro, being used anywhere else. Moreover it helps reducing the Code.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   inner classes   nested class   inner class     IBM

Try 1 Question(s) Test


 Q6. What is the benefit of inner / nested classes ?Core Java
Admin
info@buggybread.com
Ans. You can put related classes together as a single logical group.

Nested classes can access all class members of the enclosing class, which might be useful in certain cases.

Nested classes are sometimes useful for specific purposes. For example, anonymous inner classes are useful for writing simpler event-handling code with AWT/Swing.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   nested classes   inner classes   oops   classes

Try 1 Question(s) Test


 Q7. Explain Static nested Classes ?
Admin
info@buggybread.com
Ans. The accessibility (public, protected, etc.) of the static nested class is defined by the outer class.

A static nested class is not an inner class, it's a top-level nested class.

The name of the static nested class is expressed with OuterClassName.NestedClassName syntax.

When you define an inner nested class (or interface) inside an interface, the nested class is declared implicitly public and static.

Static nested classes can be declared abstract or final.

Static nested classes can extend another class or it can be used as a base class.

Static nested classes can have static members.

Static nested classes can access the members of the outer class (only static members, obviously).

The outer class can also access the members (even private members) of the nested class through an object of nested class. If you don’t declare an instance of the nested class, the outer class cannot access nested class elements directly.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   nested classes   static nested classes


 Q8. Can we have an inner class within Interface ?Core Java2016-10-24 11:18:24

Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner classes  inner class in interface  nested classes


 Q9. What is the difference between inner class and sub class ?Core Java2017-06-18 16:30:30

Ans. Inner Class is a class that is nested within another class whereas sub class is a class that extends or inherit another class.

Inner class can only be accessed using reference of outer class ( Class name , if inner class is static or object reference, if inner class is non static ) whereas Sub class is accessed directly.

In terms of memory, inner class is stored just like another class having it's own body whereas sub class carries the body of parent class as well as it's own fields in memory.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class  nested class  inner class vs sub class  nested class vs sub class      Basic



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Can an inner class be subclass of it's parent class ?Core Java2017-06-18 16:36:17

Ans. Yes that can be done

public class OuterClass {
public class InnerClass extends OuterClass {
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class  nested class  sub class      Basic


 Q11. Is this code legal in java i.e nested class within interface implementing the parent interface ?

public interface MyInterface {
public class MyClass implements MyInterface {
}
}
Core Java2017-06-18 16:37:53

Ans. Yes that's legal in java

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class  nested class  sub class      Basic


 Q12. Can an interface be defined inside a class just like we can have inner classes inside a class ?Core Java2017-06-23 08:13:43

Ans. Yes , we can have an interface that is part of a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class   inner interface  nested classes


 Q13. Which of following can be nested into another ?Core Java
a. class within another class
b. class within interface
c. interface within class
d. All of above

Ans.d. All of above



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: