Question about Inner/Outer classes

Hello!
I'm still preparing for java cert exam and have a question. If I have Outer and Inner classes like this:
Outer o = new Outer();
Outer.Inner i = o.new Inner();Does this mean that 'i' has a reference to both Outer and Inner classes. Moreover, does 'i' have a reference to the 'this' of 'o'?
Thanks,
Victor.

"i" doesn't have a reference. "i" is a reference. I think you are trying to express this:
import java.lang.reflect.*;
public class Outer {
    class Inner {
        private int foo;
    public static void main(String[] args) {
        Outer o = new Outer();
        Outer.Inner i = o.new Inner();
        for(Field field : i.getClass().getDeclaredFields()) {
            System.out.format("%s %s %s;%n", Modifier.toString(field.getModifiers()),
                ((Class)field.getGenericType()).getName(), field.getName());
}

Similar Messages

  • Question about required workshop classes for OCP

    Im working on finishing up my OCP in a few months. Quick question about the workshop class. Is there a test at the end of the week?
    Also how do most people pay for these classes? They are pretty steep and my company doesnt pay for stuff like this for me. Im paying totally out of my own pocket. Also why is the online class the same amount as the instructor lead class? Its not like im in a room at some building that Oracle has to lease for use or something.

    RedDeuce wrote:
    Im working on finishing up my OCP in a few months.What Certificate exactly are you working towards?
    Also how do most people pay for these classes? They are pretty steep and my company doesnt pay for stuff like this for me. Im paying totally out of my own pocket.Then talk to your employer again or maybe look for other jobs that support your plan better.
    Also why is the online class the same amount as the instructor lead class? Its not like im in a room at some building that Oracle has to lease for use or something.They know that you might save on expenses for travel and hotel etc.

  • Less dumb follow-up question about super/sub classes in WDJ?

    This is a follow-up question to the question which Maksim answered in this thread:
    Dumb question about super/sub classes in WDJ
    Question:
    Is there any kind of weird C++-like statement that you can put at the top of a WDJ module to force the module to interpret any reference to superclass A as a reference to some specific subclass B of A ???

    David,
    1. Java has no preprocessor, so C++ tricks are not available. Also I would not recommend such tricks even in C++ if you don't want to turn your colleagues working with same code into personal enemies.
    2. The phrase "easier to create a WDJ custom class loader " makes me smile. First, it's not that simple to interfere WDJ class loading scheme. Plus custom class loaders is not trivial Java topic per se.
    3. The problem "replace all A-s with B-s" is typically solved using one or another GoF creation patterns, like <a href="http://en.wikipedia.org/wiki/Abstract_factory_pattern">Abstract Factory</a> or <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">Factory Method</a>. You may use them with custom class loader, if you really want to
    By the way, all UI controls in WD are created using Abstract Factory (role played by view). So you may use this as good example.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Question about inner class - help please

    hi all
    i have a question about the inner class. i need to create some kind of object inside a process class. the reason for the creation of object is because i need to get some values from database and store them in an array:
    name, value, indexNum, flag
    i need to create an array of objects to hold those values and do some process in the process class. the object is only for the process class that contains it. i am not really certain how to create this inner class. i tried it with the following:
    public class process{
    class MyObject{}
    List l = new ArrayList();
    l.add(new MyObject(....));
    or should i create the object as static? what is the benifit of creating this way or static way? thanks for you help.

    for this case, i do need to create a new instance of
    this MyObject each time the process is running with a
    new message - xml. but i will be dealing with the case
    where i will need a static object to hold some
    property values for all the instances. so i suppose i
    will be using static inner class for that case.The two situations are not the same. You know the difference between instance variables and static variables, of course (although you make the usual sloppy error and call them static objects). But the meaning of "static" in the definition of an inner class is this: if you don't declare an inner class static, then an instance of that inner class must belong to an instance of its containing class. If you do declare the inner class static, then an instance of the inner class can exist on its own without any corresponding instance of the containing class. Obviously this has nothing to do with the meaning of "static" with respect to variables.

  • Few questions about Calendar / SimpleDateFormat classes

    Hi.
    I have few questions about Calendar class:
    1. How can I get only date representation (without the time)?
    after doing:
    Calendar cal = Calendar.getInstance();
    I tried to clear unecessary fields:
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.HOUR_OF_DAY);
    But after printing the time, it seems that the HOUR was not cleared:
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    System.out.println(sdf1.format(cal.getTime()));
    ---> 03/11/2004 17:00:00
    Am I missing somthing?
    2. I want to make sure that two different formats couldn't be compared. i.e., if I'll try to parse one String according to different format -- ParseException will be thrown.
    String date = "19/04/2004 13:06:10";
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    Date dateObj = sdf.parse(date);
    However, even though that formats are different, no exception is thrown and the return Date is 19/04/2004 00:00:00.
    How can I cause to exception to be thrown if formats are not identical?
    Thanks in advanced

    The Calendar class has a few of what Microsoft would call 'features'. :^)
    To clear the time, call:
    calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY), 0, 0, 0);
    If you want 'pessimistic' rather than 'optimistic' date parsing, you have two options:
    1) Call calendar.setLenient(false);
    See if that is strict enough for your needs, otherwise:
    2) Write code to ensure a stricter parsing of the string passed in. For example, you could very simply check the length of the string to determine if time data is also present.
    When parsing, a string like '02/29/02' would parse to the date '03/01/02'. Setting lenient to false may fix this, but the surest way is to do some testing and then make the parsing more pessimistic where it suits your needs.
    - Saish
    "My karma ran over your dogma." - Anon

  • Question about using container class - Map

    hi all
    i have a question about the following :
    i have two sets of data, both use a common filed as key for the map:
    A = {a,b,d,f,g,h} and B = {a,d,e,g,i,k}, each key has a value associated with.
    i need to find out the commonality, and the difference - i.e fields are in map A but not in Map B, and some fields that are in B but not in A. is there any quick method that comes with the collection class that can calculate this? thanks

    yes, the keyset will be used to access values.
    so, SetA.retainAll(SetB) will modify the SetA so that it contains keys that are in both SetA and SetB - the intersection.
    and SetA.removeAll(SetB) will modify the SetA so that it only contains keys that are in SetA, but not in SetB?
    correct?

  • Inner/Outer classes - curious matter

    Hi,
    This is from Sun Certified Programmer practice exam:
    class Outer {
       class Inner {}
    class ExtendedOuter extends Outer {
       class ExtendedInner extends Inner {}
    class Main extends Outer.Inner {
       Main( Outer ref ) {
            ref.super();
       public static void main( String[] args ) {
            new Main( new ExtendedOuter() );
    }The choices are:
    A) Compilation fails
    B) An exception is thrown at runtime
    C) The code runs with no output
    My answer was A because the line ref.super() doesn't make sense to me.
    But the correct answer is C.
    As far I as knew - super is a keyword and can be used either to access hidden members of the superclass, or to invoke specific constructor from the superclass also. What is it here???
    Could somebody explain what this line does?

    Is that because class files with no declared package
    location are automatically placed in the same
    package?Classes with no declared package are all part of an unnamed package, commonly referred to as the default package.
    In general, you should always use packages, as support for unnamed packages is implementation dependent (although all compilers and JVMs must support an unnamed package). Depending on the platform you are using, the unnamed package might include all directories and jar files on your classpath, just the current working directory, just the first directory on your classpath, or something else.
    But `ref' is not an instance of Main, but is an
    instance of ExtendedOuter (whose superclass is
    Object). Actually ExtendedOuter's superclass is Outer. However all that is important is that it is an instance of Outer, since the type checking is performed at compile time.
    So how can it be calling Main's?Because it is a superclass constructor invocation in class Main. Therefore it calls a constructor in Main's superclass. This is the syntax used to call a superclass constructor where the superclass is an inner class and the enclosing instance needs to be specified. ref is the object to be used as the enclosing instance - there is no clever trick to it - it is just a syntax.
    Also, if an instance of an innerclass exists, than an
    instance of it's outerclass must also exist. Yes, in the example the outer class instance is ref.
    Then
    won't calling the constructor of a superclass (with
    `ref.super()') be calling the constructor again after
    it (the superclass) has already existed?You can not create an object (other than instances of java.lang.Object) without calling a superclass constructor.

  • A question about the Thread class

    the code below are two way of invoke a thread to run:
    A:
    public class Test {
    public static void main(String args[]) {
         Thread myThread = new Thread(){
              public void run(){
                   System.out.println("in myThread! \n");
                   System.out.println(Thread.currentThread());
         Thread th = new Thread(myThread,"new Thread");
         th.start();
    B:
    public class Test {
    public static void main(String args[]) {
         Thread myThread = new Thread(){
              public void run(){
                   System.out.println("in myThread! \n");
                   System.out.println(Thread.currentThread());
         myThread.start();
    i have read many free software's source code, and find many people would like to implement it like A instead of B
    so my question is why A is better than B.
    thanks!!

    A is actually using the constructor which accepts a Runnable. In your case, since you are overriding only run(), you could have simply implemented the Runnable and created the thread th. However, in this model you are using a Runnable you are actually separating the task from the Thread. In B, thread is actually the task which couples them tightly. Therefore, from design point of view, A is recommended with Runnable rather than a Thread unless you have specific reasons to do that.

  • OK: simple question about video out

    My new mac mini should arrive today. I'm taking it one step at a time but planning down the road as I hope to hook it to my TV for Netflix streaming, Hulu, etc. I've ordered the S-Video adapter so I'll be good there.
    My question: I know that to drive a second monitor (not mirrored) that a third party, usually USB solution is needed. But what if I just want to mirror out to my TV what is shown on the monitor? Will a DVI splitter do the job?

    A splitter will generally not work - or at least that well - because it means the mini will receive two separate signals from the displays indicating conflicting possible settings. It would only then work at resolutions which are common to both displays - typically 640x480 and 800x600.
    What complicates it more in your case is that since you want to drive the TV with the DVI-to-S-Video adapter, if you were to add a splitter before that cable, it would eradicate the S-video component since that is catered for by the adapter alone. And clearly you can't add a splitter after the adapter.
    There is no real, easy way to add dual display use to a mini, but the recently released USB adapter and the Matrox dual-head-to-go are probably the most viable. Even then, in as far as the former, the USB display will be relatively slow, and in the latter, you will be limited to what amounts to two 1024x768 screens - in effect, your TV and a 15" LCD. It is also not clear whether the Matrox unit passes the S-video component of the mini's output, meaning that if it does not, it can also not be used if a TV is being connected by composite or S-video.

  • Question about zeroing out data...

    I'm currently zeroing out my Time Capsule's hard drive and starting fresh with backing up. I started doing a 7 pass method the other day, but figured it was overkill and bad on the hard drive, so I stopped it a quarter of the way through pass 2. Does this mean that at least the one full pass was done successfully? Also, to make sure that everything is truly zeroed out, I started a one-time zero out erase. So, does this mean, then, that my TC truly has been zeroed out twice for starting over on my backups?
    And, while we're on the subject, I did some research on zeroing out data. Most people are in agreement that doing one pass is good enough. Apple recommends twice for a fully secure wipe. While researching this, I found that some claim that zeroing out a hard drive during a 7 pass and 35 pass method significantly decreases the lifespan of a hard drive. Is this myth busted or confirmed? Also, is zeroing out data only once already harmful to an HD's lifespan?

    William Boyd, Jr. wrote:
    apple_kmj wrote:
    I'm currently zeroing out my Time Capsule's hard drive and starting fresh with backing up.
    I'll leave to others the answering of your questions, but I have one of my own: What are you hoping to accomplish by zeroing out your Time Capsule's drive? I would only consider that useful if I were planning to sell or otherwise dispose of a Time Capsule.
    I heard that it's the best way to go if you have a lot of data synced and you don't want to individually pick out data to delete. Also, backups were taking a while, and I noticed that my Time Machine had nothing on it even though my Time Capsule showed as having almost 80 GB of data backed up. So, just to eliminate any potential problems, I zeroed out data and started over again.

  • Beginner's question about naming helper classes

    Hello,
    I am building a pretty basic multi-tier application. I want to reduce a much as possible the dependencies between the web tier and the ejb tier. Ideally I would like for the web tier to construct a request object (of class MyRequest) and send it to the ejb tier that would then return a results object (of class MyResults).
    These would therefore be the only two classes that BOTH the ejb and web tier would be aware of. All other classes would either belong to the web tier OR the ejb tier.
    My question relates to the naming of these two classes. I would like to have different package names for the two classes as follows:
    -web-tier request object will be of type com.mycompany.web.MyRequest
    -ejb-tier request object will be of type com.mycompany.ejb.MyRequest
    -web-tier results object will be of type com.mycompany.web.MyResults
    -ejb-tier results object will be of type com.mycompany.ejb.MyResults
    I am getting errors with that. Is there a way around it?
    Thanks in advance,
    Julien Martin.

    Hello PinkyDead and thanks for your answer,
    I got the errors on another project and can't remember which. Class Cast Exceptions perhaps. I had to change the package names so that they matched in the web tier and the ejb tier. (which is what I don't like).
    As far as the new project is concerned I am trying to design the application as well as possible and your comments are therefore useful. Better getting the design right before starting coding.
    Can you or anyone tell me what architecture would be better that the one I proposed?? Don't you agree that at least some classes have to be shared by the web tier and the ejb tier? How can it be otherwise?
    Thanks in advance,
    Julien.

  • Hello question about blown out layout and designer

    hello im a web designer....my format is to slice my layout in fireworks....then I bring things into dreamweaver and then place flash files into placed blank spots...........my problem is I notice things get out of line and blown out.....how can i fix this?
    example:---http://sites4sight.com/Zdara/Lounge.html...this is fine in safari and IE?

    Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The helpers over there are more knowledgeable about web page development issues with Firefox. <br />
    http://forums.mozillazine.org/viewforum.php?f=25 <br />
    You'll need to register and login to be able to post in that forum.

  • Question about laying out a maze and buttons

    I am very new to SWING, and I just finally figured out how to draw my maze. I am drawing it on a JPanel, using the layout manager. Then I plop that JPanel onto a JFrame. But now i want to have a program that has the JPanel, which is basically the maze, and two buttons far below, kind of like how a java minesweep game would look. Can somebody give me a hint as to how this is done? Do I have to put another JPanel, that holds this "maze JPanel," and which also holds 2 other places for buttons? Because if I just add the buttons to this JPanel, everythinig will be squished together right? How would a professional program lay this out?

    Well, the idea is you plan your layout ahead of time. The typical look of an application is:
    1) toolbar
    2) main window
    3) statusbar
    This layout suits the BorderLayout perfectly.
    Then take a look at you main window. If you main window consists of a single component then just add it to the center of the BorderLayout. If, however, it consists of multiple components then create a new JPanel add it to the center and determine the best LayoutManager to use. This can be a recursive process.
    So, to answer your question, yes, you would nest layout managers within layout managers (or JPanels within JPanels).

  • Question  about Abstract,Final Class

    when we are using final keyword along with class definition .we are making that class final, means we can’t extend that class. The same thing happens when we make our constructors private. From usability perspective both are same ? or is there any difference?
    Secondly accounting to java syntax a class can be either final or abstract and not both .Then why language specification doesn't impose any restriction on making abstract classes constructor private. We can create an Abstract class with private Constructor (Basically utility class with all methods are static) ,to make this class Singleton .This situation is equal to abstract final class ?
    Thanks,
    Paul.

    EJP wrote:
    when we are using final keyword along with class definition .we are making that class final, means we can’t extend that class. The same thing happens when we make our constructors private.No it doesn't.
    Secondly accounting to java syntax a class can be either final or abstract and not both.Correct.
    Then why language specification doesn't impose any restriction on making abstract classes constructor private.Why should it? That proposition doesn't follow from your previous sentence.I think OP is asking about this case
    public abstract class WTF {
      private WTF() {}
      private WTF(...) {}
    }where the class is abstract and all the c'tors are final. It's an abstract class that cannot be extended, much like a final abstract class would be if it were allowed. So, since purpose of abstract classes is to be extended, the OP seems to be asking, "Why can we, in this fashion, create an abstract class that cannot be extended?"
    I don't know the answer to that, but I would guess that, while final is an explicit syntactical element for the purpose of making a class non-extensible, in the all-private-c'tors case, the non-extensibility is simply a side effect, and probably enough of a corner case that it wasn't worth the effort to explicitly forbid it in the spec.
    I also think it's something not worth thinking much about. It was certainly not a key point of some grand design.

  • Looking for tjacobs to answer a few questions about his StandardPrint Class

    Hello,
    Hopefully tjacobs will see this post and answer it as soon as he has time. I am trying to use your Standard Print class in a program I am developing to Print a JPanel in a JScrollPane and am running into trouble. I will have more info for you if you can find it in your heart to reply.
    Thank you,
    Ray Jaramillo

    I'm in exactly the same boat as you... gonna be using it as my primary computer, graduating college soon, and my first mac. I'll be going with the 13 inch MacBook Air.
    The Pro and the Air are nearly identical performance-wise and so that means the only advantage of the Pro is the storage space (unless you count the cd drive as an advantage). The Air is way more portable and has a better display, I don't know about you but my current cd drive rarely gets used so might as well get rid of it.
    I have also compared them side-by-side in the store and that was really what won me over to the Air. The 11-inch Air was there too but the screen just seems too small, especially if you are doing work/writing essays etc.
    Hope that helped

Maybe you are looking for

  • 2 Apple-IDs on my Mac

    Due to changes, I have now 2 Apple-IDs on my Mac, iPad - one "normal" and a second one under "iCloud". Who knows a solution?

  • I have a question so help me out

    Yeah so anyway, in itunes i like have these folders but when i try to "drag" the music or song or whatever into the folder it doesnt work. why. thanks

  • My listener was not working

    Dear all, could u plz find the below error Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=lei.four-soft.com)(PORT=1520))) TNS-12547: TNS:lost contact TNS-12560: TNS:protocol adapter error TNS-00517: Lost contact Linux Error: 104: Connection

  • Deplying multiple mappings at a time

    Hi, I am new to owb, If i register the locations I have to deploy all the mappings. And it is taking long time deploy all the mappings in owb. Is there any way I can deploy them through unix script so that hanging of the owb client can be avoided and

  • Setting the Priority on a Process/Application

    Actually aksed this question in the Foundation discussion group but think it is better suited here... Hi I have a JBoss turnkey install of LiveCycle ES2 in production. One of the applications runs a large batch job in the evenings. This all works fin