Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Which statement is true about a non-static inner class? (Sun's sample) - It is accessible from any other class. - It can only be instantiated in the enclosing class. - It can access private instance variables in the enclosing object. Though i know answer is 3 i would like someone to discuss about first two options.Thanx in advance
right 3 is true. reg. first point: the (non-static) inner class is not accessible without an instance of the enclosing class reg. second point: an (non-static) inner class may be instantiated anywhere provided we have an instance of the enclosing class HIH ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Hello Leena, I have created a chart about the relationship of innerclasses with others.It is available here Regards Gurpreet Sachdeva For Mock Exams, FAQ and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: http://www.go4java.20m.com
Regards<BR>Gurpreet Sachdeva<P>For Mock Exams, FAQ, Exam tips and some useful information about Bitshift operator, inner classes, garbage collection,etc please visit: <A HREF="http://www.go4java.lookscool.com" TARGET=_blank rel="nofollow">http://www.go4java.lookscool.com</A>
Hello Leena, Meaning of Access Modifier for Top - Level Class and Inner Class are not same always. Although to know their behaviour u can consider them as a method of top-level class. and Inner classes are non-static classes defined within other classes Here is a code example for Inner class and their creation. class Outer { class Inner {} // class definition within the // the body of class Outer } the compiled class files for the above are: Outer.class and Outer$Inner.class So, leena we can consider that Inner class just uses naming convention for their nomenclature. the Inner class type is: Outer.Inner and Instances of inner classes can be created in a number of ways Create an Outer class object: Outer o1 = new Outer(); Then create an Inner class object: Outer.Inner i1 = o1.new Inner(); but u cann't create an object of Inner class without instantiating the outer class.
Creating the inner class directly: Outer.Inner i2 = new Outer().new Inner();
Creating one from within the outer class constructor class Outer { Outer() { new Inner(); } } inner classes may have no declared access modifier, defaulting the class access to package or, inner classes may be declared public, protected, private, abstract, static or final class Outer { public class PublicInner{} protected class ProtectedInner {} private class PrivateInner{} abstract class AbstractInner {} final class FinalInner {} static class StaticInner {} } each instance of a non-static inner class is associated with an instance of their outer class static inner classes are a special case. inner classes may not declare static initializers or static members unless they are compile time constants ie static final var = value; you cannot declare an interface as a member of an inner class; interfaces are never inner inner classes may inherit static members the inner class can access the variables and methods declared in the outer class to refer to a field or method in the outer class instance from within the inner class, use Outer.this.fldname Hope this helps, Nisheeth Kaushal