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.
Similar Messages
-
I got a question about Object class in AS3 recently.
I typed some testing codes as following:
var cls:Class = Object;
var cst:* = Object.prototype.constructor;
trace( cls === cst); // true
so cls & cst are the same thing ( the Object ).
var obj:Object = new Object();
var cst2:* = obj.constructor.constructor;
var cst3:* = obj.constructor.constructor.c.constructor;
var cst5:* = Object.prototype.constructoronstructor;
var cst4:* = Object.prototype.constructor.constructor.constructor;
var cst6:* = cls.constructor;
trace(cst2 === cst3 && cst3 === cst4 && cst4 === cst5 && cst5 === cst6); //true
trace( cst == cst2) // false
I debugged into these codes and found that cst & cst2 had the same content but not the same object,
so why cst & cst2 don't point to the same object?
Also, I can create an object by
" var obj:Object = new cst();"
but
" var obj:Object = new cst2();"
throws an exception said that cst2 is not a constructor.
Anyone can help? many thanks!I used "describeType" and found that "cst2" is actually "Class" class.
So,
trace(cst2 === Class); // true
That's what I want to know, Thank you. -
i just updated my 3gs to iOS5 and it keeps on saying cannot activate iphone.. after searching videos how to activate it.. i can't tap my three fingers because there is no clock showing on my screen. how do i go about it? help please.
i have the exact same problem and im still currently trying to figure out how to activate it
-
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());
} -
Two questions about defining class, pls help me
Hi, guys. I'm green hand and here are two questions puzzled me several days.
We know such example as below is a case of cyclic inheritance
class Base extends Base{
But I can't figure out why below is a case of cyclic inheritance too
class Base{
class Derived extends Base{
class Base{
I can't find the clue of cyclic inheritance. It's quite different from the case that a class extends itself or its subclass.
Another question is why the inner class can't have the same name of outer?
class Base{
class Base{
The compiler says Base is already defined in unnamed package. As it says, the inner class is defined in the
unnamed package, but we know below is correct.
class Base{
class Basic{
class Derived {
class Basic{
We know it's correct. But as the compiler says above, the different two inner class Basic are both defined in the
unnamed package. Why it's valid and why above is invalid?Hi,
Can you tell us which product (s) you are referring to ? Can you also tell us the nature of your business requirements so that we can offer some suggestions ?
Regards,
Sandeep -
PLEASE HELP ME!!! THANK YOU!!
Reset Security Questions
Frequently asked questions about Apple ID
Manage My Apple ID
Or you can email iTunes Support at iTunes Store Support.
If all else fails:
1. Go to: Apple Express Lane;
2. Under Product Categories choose iTunes;
3. Then choose iTunes Store;
4. Then choose Account Management;
5. Now choose iTunes Store Security and answer the bullet questions, then click
Continue;
6. Sign in with your Apple ID and press Continue;
7. Under Contact Options fill out the information and advise iTunes that you would
like your security/challenge questions reset;
8. Click Send/Continue.
You should get a response within 24 hours by email.
In the event you are unsuccessful then contact AppleCare - Contacting Apple for support and service.
Another user had success doing the following:
I got some help from an apple assistant on the phone. It is kind of round about way to get in.
Here is what he said to do and it is working for me...
a. on the device that is asking you for the security questions go to "settings", > "store" >
tap the Apple ID and choose view"Apple ID" and sign in.
b. Tap on payment information and add a credit/debit card of your preference then select
"done", in the upper right corner
c. sign out and back into iTunes on the device by going to "settings"> "store" > tap the
Apple ID and choose "sign-out" > Tap "sign -in" > "use existing Apple ID" and you
should be asked to verify your security code for the credit /debit card and NOT the
security questions.
d. At this time you can remove the card by going back in to edit the payment info and
selecting "none" as the card type then saving the changes by selecting "done". You
should now be able to use your iTunes store credit without answering the security
questions.
It's working for me ...I just have to put in my 3 digit security pin from the credit card I am using.
Good Luck friends! -
HT5312 need to reset security questions dont know how help please
I went to buy a song and it makes me put in security questions. I forgot the answers and i cant figure out how to fix it. Please Help!
1. See my User Tip for some help: Some Solutions for Resetting Forgotten Security Questions: Apple Support Communities.
2. Here are two different but direct methods:
a. Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
b. Call Apple Support in your country: Customer Service: Contacting Apple for support
and service.
3. For other queries about Apple ID see Frequently asked questions about Apple ID.
4. Rescue email address and how to reset Apple ID security questions -
Design question on inner class
I have an app, with a JPanel. The way I have it setup right now is the JPanel is an inner class with an overloaded constructor. I call the inner class depending on the arguements. this is done repeatedly in my program.
My question is: Should I be doing it this way or maybe as a method that returns the updated JPanel? Can this cause serious memory problems?
example
private void CreateTextfields(int q, int c){
// c = number of choices selected from other JComboBox
// q = question selected from combo box
// questions is the arrylist containing all questions
AnswerPanel answerPanel;
answerPanel = null;
textFieldPanel.removeAll();
if( questions.isEmpty() && c > 0 ){
answerPanel = new AnswerPanel(c);
else if( !questions.isEmpty() && c == 0 ){
answerPanel = new AnswerPanel(q, listOfAnswers);
else if( !questions.isEmpty() && c > 0 ){
clearLogic();
answerPanel = new AnswerPanel(q, listOfAnswers, c);
textFieldPanel.add( answerPanel, BorderLayout.CENTER ); Thanks
Jim<<serious memory problems>>
Probably not. But it seems wasteful to keep creating a new object just to set some properties. Why not make a single AnswerPanel, with overloaded setContents() functions?
Not that I'm a Swing expert or anything....
HTH,
Ken -
Hello, I was just wondering if someone can help me understand inner classes a little. If I have the following code:
class Parent
private String myString = new String(�I am parent�);
public void writeIt()
System.out.println(myString);
public void displayIt()
System.out.println((new InnerParent()).readMyString());
class InnerParent
public String readMyString()
return myString;
class Child extends Parent
private String myString = new String(�I am child�);
public void writeIt()
System.out.println(myString);
If we execute the following lines on the code
Child myChild = new Child();
Parent myParent = new Parent();
myChild.writeIt();
myParent.writeIt();
myChild.displayIt();
myParent.displayIt();
Why does the following code display?
I am child
I am child
I am parent
I am parent
==
Thanks!Child myChild = new Child();
Parent myParent = new myChild();you again made a mistake,
it should be
Child myChild = new Child();
Parent myParent = new Child();
and now the output is
I am child
I am child
I am parent
I am parent
because, myChild.writeIt(); displays the stirng, I am child, straightforward, when it comes to myParent.writeIt(); it displays the string I am child because, myParent is of the type Child() which has been casted back to Parent, since child extends parent this can be done, and so, it just behaves as if it is a child, and so it displays I am child. when it comes to myChild.displayIt(), it uses the string in the Parent class, since it extends Parent and it does not override that method, it has to use that string ,and so it displays I am Parent, and similarly for the myParent.displayIt(), also it displays I am Parent. Hope you Understood now. -
I have a class that has 3 inner classes, on class read the colors and font settings, how can I pass this class to the 2 other inner classes
Here is a watered down version of code:
class MainClass{
public MainClass(){
// do some stuff
innerClass3 ic = new innerClass3();// I need to pass this to the other inner classes
layeredPane.add( new innerClass1( some Variable), 1);
layeredPane.add( new innerClass2( anotherVariable), 2 );
class innerClass1 extends JTextPane{
public innerClass1( String s ){
// instead of doing this
innerClass3 ic = new innerClass3();
setBackground(ic.getBackground() );
class innerClass2 extends JPanel{
public innerClass2( String[] z){
// and this again
innerClass3 ic = new innerClass3();
setForeground(ic.getFontClor());
class innerClass3{
Color background;
Color foreground;
public innerClass(){
setColors();
public void setColors(){
background = Color.blue;
foreground = Color.red;
public Color getBackground(){
return background;
public Color getFontColor(){
return foreground;
Thanks for the reply
Works well for first screen, but I recall the innerClasses(1 and 2) from an actionPerformed in innerClass2 and I keep getting nullPointerError when referring to innerClass3. Each screen will have different fonts and colors, so I need it to update after each button click.
// this is inside innerClass2( it's panel with buttons )
// the next screens graphics will depend on which button is selected
public void mouseReleased(final java.awt.event.MouseEvent e) {
layeredPane.removeAll();
currentQuestionNumber++;
question = questionText[currentQuestionNumber] ;
// adds a JTextPane with question
layeredPane.add(new innerClass1(question, ic), 1 );
// adds a JPanel with buttons
layeredPane.add(new innerClass2( currentQuestionNumber, ic ), 3 );Will be tearing hair out soon
Jim -
Question about dynamic class loading with thread built in
Hi ,
I am trying to load a class with a thread built in from the network.
I write my network classloader, convert the class to a byte array and transmit over the network using socket. This step seems fine but when I tried to load the class at the receiver, some exception happens,"
the reported exception is that :
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: SampleProject/Application$1
my class name is "SampleProject . Application", the $1 I think it may refers to the thread built in the "Application".
Could any one give me some hint for how to dynamic load such class file with thread built in over the network?
Thank you!
Best Regards,
Song GuoException in thread "Thread-2"
java.lang.NoClassDefFoundError:
SampleProject/Application$1That means that the receiving end can't find an anonymous inner class which you have in the Application class. (The anonymous clas is given the synthetic name 1). Check your bin/classes folder you will have a class there with the name Application$1.class
Kaj -
Question about abstract classes and instances
I have just read about abstract classes and have learned that they cannot be instantiated.
I am doing some exercises and have done a class named "Person" and an abstract class named "Animal".
I want to create a method in "Person" that makes it possible to set more animals to Person objects.
So I wrote this method in class Person and compiled it and did not get any errors, but will this work later when I run the main-method?
public void addAnimal(Animal newAnimal)
animal.add(newAnimal);
}Is newAnimal not an instance?Roxxor wrote:
Ok, but why is it necessary with constructors in abstract classes if we don�t use them (because what I have understand, constructors are used to create objects)?Constructors don't create objects. The new operator creates objects. An object's c'tor is invoked after the object has already been created. The c'tors job is to initialize the newly-created object to a valid state. Whenever a child object is created, the parent's c'tor is run before the child's c'tor, so that by the time we're inside the child's c'tor, setting up the child's state, we know that the parent (or rather the "parent part" of the object we're initializing) is in a valid state.
Constructor rules:
1) Every class has at least one ctor.
1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
1.3) Constructors are not inherited.
2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed. -
Clarification about inner class - why use it?
hi all
i just have a request to get some clarification on inner class. why do we use it and is it common to use it? thanks.hi all
i just have a request to get some clarification on
inner class. why do we use it and is it common to use
it? thanks.It is realtively common. You may use one if you need to implement a class that's only relevant to one other class, like a data container or EventListener. Since it's probably interlocking tightlyx with its "outer" class, but doesn't need to be in reach of any other classes, its visibility can be confined to the outer class itself. Plus, objects from inner classes - if not declared static - are always tied to the existance of an outer class instance. -
A question about openssl, pls help me
hi,all
I'm a student from China. Now I dowload the openssl package to study the cryptography algorithm. I have read some books such as Applied Cryptography by Bruce Schneier. But Mr. Eric Young's programs make me in sea, e.g. in CAST program package, there are CAST_ecb_encrypt , CAST_cfb64_encrypt , CAST_cbc_encrypt and CAST_ofb64_encrypt function. Which should I use ?
I teach myself Cryptography, so none can answer my question. Can you help me?
Thanx!void CAST_set_key(CAST_KEY key, int len, const unsigned char data);
void CAST_ecb_encrypt(const unsigned char in,unsigned char out,CAST_KEY *key
int enc);
void CAST_encrypt(CAST_LONG data,CAST_KEY key);
void CAST_decrypt(CAST_LONG data,CAST_KEY key);
void CAST_cbc_encrypt(const unsigned char in, unsigned char out, long length
CAST_KEY ks, unsigned char iv, int enc);
void CAST_cfb64_encrypt(const unsigned char in, unsigned char out,
long length, CAST_KEY schedule, unsigned char ivec,
int *num, int enc);
void CAST_ofb64_encrypt(const unsigned char in, unsigned char out,
long length, CAST_KEY schedule, unsigned char ivec,
int *num); -
Basic question about Flash video. Please Help
Hello,
Sorry for the noob question but I'm struggling with the basic
understanding about the Flash video.
I just need to reduce a large video file to a small size with
a nice quality and the Flash Video Encoder does very god job with
that. But when I double click the compressed .flv file it opens as
a blank screen in the stand alone player without playing any video.
I can use Dreamweaver to produce a web page playing the file, but I
don't need this file for posting it on a web page, I just want the
file smaller and to simply play it on my computer or send it to
others.
What is the way to do this?
I appreciate your help.It sounds like you're not having problems with the actual
compression of the videos, just the playback, correct? All you need
is a standalone player that plays FLVs. Like Quicktime Player plays
MOVs, and Windows Media Player plays WMVs, you need something to
play the FLV files. There are many free options available. On a
mac, I use something called, strangely enough, SWF & FLV
Player. You can find it here:
http://mac.eltima.com/freeflashplayer.html
Just do a search for FLV players and you should find
something appropriate. The only downside is you'll need to make
sure anyone you're distributing the videos to also has an FLV
player. If you're sending your files to just a few people, no big
deal. If this is for the public in general, you would want to embed
a Flash video player in an HTML page and send it like that.
Hope that helps.
Maybe you are looking for
-
Itunes Installation Damaged Error Windows 7
For weeks Itunes has been begging me to update my software to the new software which i didn't do until yesterday. As i did, all my music except music i bought off of itunes was gone, just gone. my playlists were all gone and the layout of the itunes
-
Local Currency - Translation Date Type
Hi: We are on ECC 6.0 with New GL. I wanted to check if we can change the Translation Date Type for 1st local currency (10) from Translation date to document date? There are three options in this field - Posting date, document date and translation da
-
Apple's Mail program can't handle junk mail
I've had this machine for almost two months now and I'm STILL having problems with Apple's mail program: 1. It doesn't recognize junk mail. Although I've been in "train" mode for almost two months, it STILL doesn't recognize ANYTHING as junk mail, ev
-
How do I merge three director files into one?
Hi! So I'm doing a school project. We're making a program. We have a startpage with two buttons. Then we have two other pages. One of the pages is a quiz, so it has different questions and you move along in the quiz when you click on one of the three
-
Looking to use laptop as second monitor
Hi all. I'm on an editing job with a client. We have two macbook pros. I'm editing on one. We're wondering if I can use the second one as a monitor and if so how to do it. Anyone know? tks in advance for help.