Small inheritance question
Got a small quesiton about inheritance.
I have a 'User' Class and extending that class is 'Player' and 'Enemy'.
Player class and Enemy class contains extra stuff like different image and moves different.
When I create a new player do I create an instance of the 'User' class or the 'Player' class?
Also,
If values change in the 'Player' class do the values also change in te 'User' class?
I am fairly new to java.
Thanks
MarcLeslie120 wrote:
Got a small quesiton about inheritance.
I have a 'User' Class and extending that class is 'Player' and 'Enemy'.Sounds odd. Aren't some players also your enemy? Or is Player me, and everybody else is Enemy?
Player class and Enemy class contains extra stuff like different image and moves different.Okay. If it's just different, that's one thing. If it's adding extra methods, you probably don't want to inherit.
When I create a new player do I create an instance of the 'User' class or the 'Player' class?If it's going to be a Player, you need to create a Player.
If values change in the 'Player' class do the values also change in te 'User' class?If you mean an instance variable (a non-static member variable), then there aren't two separate objects. There's just one object, that is both a Player and a User. The variable exists only once.
Your inheritance hierarchy smells funny, but without more details about what these classes represent and what you're trying to accomplish, it's hard to provide concrete advice.
Similar Messages
-
Email photographs not seen, photograph are replaced with a small blue question mark.....what do I need to do to see the pictures ?
Hello tomfromridgetown,
Welcome to the Apple Support Communities!
I understand that sometimes when you receive an email it contains a small box with a question mark for the attachment. It sounds like what you may be seeing is a windmill.dat attachment. Please review the attached article for information on what these attachments are and how to avoid them in the future.
Mac OS X Mail: What is a winmail.dat attachment? - Apple Support
Have a great day,
Joe -
Advice for Building Small Network Question
Hello,
I am building a small network environment which will connect to a larger office, scalability is important. We will begin having about 30 users which will all need VOIP services. The VOIP services will be hosted by a cloud provider. My question is as of now I am looking to obtain a Cisco 2921 ISR Router and then a Cisco 2960-X 48Gig POE, and my main question is I am confident the switch can handle the power and operation of the phones but just to make sure I should not run into any problems with the router as far as forwarding the data, correct? Any other comments or suggestions would be appreciated.
Thanks,
JoeDuplicate post.
Go HERE. -
Constructor Inheritance Question
Here's a quote from the Java Tutorials at http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html :
"All classes have at least one constructor. If a class does not explicitly declare any, the Java compiler automatically provides a no-argument constructor, called the default constructor. This default constructor calls the class parent's no-argument constructor, or the Object constructor if the class has no other parent. If the parent has no constructor (Object does have one), the compiler will reject the program."
In order to fully understand this concept, I created two classes: a ClassParent and a ClassChild.
public class ClassParent
public static void main(String[] args) {
ClassParent tester = new ClassParent();
public class ClassChild extends ClassParent
public static void main(String[] args) {
ClassChild child = new ClassChild();
}Both classes compiled successfully, which raised the following question:
I understand that the ClassParent default constructor calls the Object's no-argument constructor.
Does the ClassChild also call the Object's constructor once it realizes that the ClassParent does not have a no-argument constructor?
And a somewhat non-related question:
Seeing how ClassParent calls Object's no-argument constructor if it does not have one of its own, does it also extend the Object class?
Edit: After running the following code, I realized that the answer to my last question is yes:
public class ClassParent
public static void main(String[] args) {
ClassParent tester = new ClassParent();
boolean test = tester instanceof Object;
System.out.println(test);
}Edited by: youmefriend722 on May 26, 2008 1:54 PMyoumefriend722 wrote:
I think I'm getting a basic grasp now but want to make sure that I'm not misunderstanding anything.
Constructor inheritance:
If a no-argument constructor is invoked but one isn't declared in that class, the superclass's no-argument constructor will be invoked. Well, sort of. If you invoke a constructor that doesn't exist, you get an error. Keep in mind that the invocation and the constructor may both be automatically supplied by the compiler, and that the compiler won't automatically create a no-arg constructor for a class if you define any constructors for that class.
So if you don't define any constructors in a class, then a no-arg one is created automatically (at compile time) and (at runtime) when you instantiate that class, that no-arg constructor will try to invoke the superclass's no-arg constructor.
But suppose you do define a constructor, one that takes an argument. Then if you try to invoke a no-arg constructor on that class, you'll get an error, and the superclass's no-arg constructor won't be invoked (because the error happens first).
If the superclass does not have a constructor, then the superclass's superclass's constructor will be invoked.No. That never happens. Every class has a constructor (although it might have permissions which make it inaccessible, which is a whole other issue we'll worry about later).
If the superclass does have a constructor but doesn't have a no-argument constructor, then there will be a compile-time error.Only if you try to invoke the no-arg constructor, which might happen implicitly. For example, if you write a superclass with a 2-arg constructor, and you write a subclass with a 1-arg constructor, and the 1-arg subclass's constructor invokes the superclass's 2-arg constructor, then there's no problem, even though in this example, the superclass doesn't have a no-arg constructor.
Constructors in general:
In every constructor, the superclass's no-argument constructor will be invoked if the none of the superclass's constructors are explicitly invoked.Yeah, I think that's right. -
This just occurred to me. I read the other day that all classes inherit Object. So if I have a class defined as public class A {
}and I call toString() on an instance of this class, I get Objects toString implementation (assuming it has not been overridden). OK, this I understand.
Now if instead I havepublic class A extends B {
}and I call toString() on A, assuming it is not overridden in either A or B, I will still get Objects toString method. My question is, does A still extend Object, or does it inherit the fact that B extends Object? And what happens if I override toString() in B - what will I get if i call toString on an instance of A?java.lang.Object is at the root of all class inheritance hierarchies in Java. Therefore, all classes inherit from java.lang.Object, either directly or indirectly.
When you call a method on an object of class Foo, Foo's inheritance hierarchy is traced starting with Foo and going all the way back to java.lang.Object, looking for an implementation of the method. The first implementation encountered is the one that gets used. So in your example calling toString on an instance of class A will result in B's toString method being executed.
Hope this makes sense. -
IMac screen gone white with small flashing question mark in centre of screen
iMac screen went blank (greyish white) on startup and now has a small question mark flashing in the middle of the screen.
Any idea what I should do?Thank you.
Was just trying the routh of a USB keyboard & mouse and by holding down the 'option' key, the request for wireless network popped up; after connecting, 'internet support' popped up and now it's showing a small rotating globe and a horizontal hourglass with 1:23 to go still....
Let's see how this does -
For loops & inheritance question
I am trying this exercise dealing w/inheritance. I enter at command line a random number of c's, s's and m's. for checking,savings and money market. I then parse the string and check for the character. From there I create one of the accounts. then I am supposed to make a report that displays the past 3 months activities. the first account created gets 500 deposit the from there each account after the first gets an additional 400. so it would be: 500,900,1300,etc. Here is what I have so far, but the report part is where I can't figure out exactly how to go about solving it. Thanks in advance.
public static void main( String args[] ){
int intDeposit = 500;
char charTest;
Object [] objArray = new Object[args[0].length()];
for ( int j = 0; j < 3; j ++ ){ System.out.println( "Month " + ( j +1 ) + ":" );
for( int i = 0; i < args[ 0 ].length(); i ++ ){
charTest = args[ 0 ].charAt( i );
if (charTest == 'c' ){
BankAccount at = new CheckingAccount( intDeposit );
objArray=at;
else if( charTest == 's' ){
BankAccount at = new SavingsAccount( intDeposit );
objArray[i]=at;
else if( charTest == 'm' ){
BankAccount at = new MoneyMarket( intDeposit );
objArray[i]=at;
else{
System.out.println( "invalid input" );
}//else
intDeposit += 400;
System.out.println();
}//for j
for (int counter = 0; counter < objArray.length; counter ++ ){
System.out.println( "Account Type: " +
objArray[counter].toString() );
System.out.println( "Initial Balance: " +
(BankAccount) objArray[counter].getCurrentBalance() );
System.out.println( "TotalDeposits: " + objArray[counter].getTotalDeposits() );
System.out.println();
}//for i
}//main
}//TestBankAccount.java\The only thing I think is wrong is the following line:
System.out.println( "Initial Balance: " + (BankAccount) objArray[counter].getCurrentBalance() );
Should be:
System.out.println( "Initial Balance: " + ((BankAccount) objArray[counter]).getCurrentBalance() ); -
Say a superclass has 3 methods and 3 properties. NExt, I create a subclass which overrides these same 3 methods and properties. Either way, my question really is this... When casting up and down, when it is a subclass and a super class reference, are the properties preserved when it is cast(implicitly) up to a superclass reference, so that, in case it needs to be cast back down (explicitly) to its original subclass form, the subclass properties can still be referred to? Are the original variables still preserved (much like a static variable)?
are the properties preserved when it is cast(implicitly) up to
a superclass reference, so that, in case it needs to be cast backAn object instance does not change when it's casted into a superclass reference. This means it can be casted back (if this weren't the case, then all methods that return Object would be pretty useless).
In addition, accessing an object method via a superclass reference does not mean that you'll invoke a superclass method. Instead, it invokes the method appropriate to the object (otherwise overriding and polymorphism would be pretty useless).
However, accessing an object's instance variable via a superclass reference does access the superclass variable, not the subclass variable.
I would suggest playing with this for a while ... here's something to start with:
public class DROCPDP
public static void main( String argv[] )
throws Exception
Base a = new Base();
Sub b = new Sub();
Base c = (Base)b;
Sub d = (Sub)c;
System.out.println("\nOperations on A:");
System.out.println("a.var = " + a.var);
a.method();
System.out.println("\nOperations on B:");
System.out.println("b.var = " + b.var);
b.method();
System.out.println("\nOperations on C:");
System.out.println("c.var = " + c.var);
c.method();
System.out.println("\nOperations on D:");
System.out.println("d.var = " + d.var);
d.method();
private static class Base
public String var = "Base";
public void method()
System.out.println("Called Base.method; variable = " + var);
private static class Sub extends Base
public String var = "Sub";
public void method()
System.out.println("Called Sub.method; variable = " + var);
} -
I'm trying to create a document with text sizes smaller than 6 pt. The problem is that the "Other" option in the drop-down menu is grayed out and I don't know why. I tried several different fonts and different types of fonts, but they all had the same problem.
For the moment, I'm creating my text in Illustrator, then cutting and pasting it into InDesign, but I'd rather just create it in InDesign directly.
Any help would be appreciated.Didn't read the part about the drop-down menu. Was just looking in the character palette. Nonetheless, it may be the same thing. If the Other field in Cindy's character palette is greyed out as well, which I'm guessing it is, inputing a value there may jump start the whole thing.
-
IPhone 3G uses Smaller Battery / Question
According to this tear down:
http://live.ifixit.com/Guide/First-Look/iPhone3G
The battery is actually lower in capacity than of the original iPhone.
My question is: Would it be possible to replace the included Battery with a larger size?Ouch! That's certainly a bummer... why would Apple do this? If they complain 3G ***** down more battery (the reason why 3G was not included in the original iPhone, and the fact that the 3G settings screen says it too), you would think that the iPhone 3G would have at least the same battery capacity if not more.
I think this is a conspiracy to get people to subscribe to mobile me to get push email instead of people like me who set my phone to fetch mail every 15 minutes. My battery on the iPhone 3G is down to 10% at night with very little use throughout the day (other than checking mail and a couple of phone calls). And I only have 1 email account set up.
Compared to my original iPhone, I have 3 email accounts that are checked every 15 minutes, and I'm usually at 40% battery left when I go to bed at night. -
Hello,
I got some questions related to internationalisation with ADF BC4J and ADF Faces.
selection facet of af:table
The column header always seem to use a "Select", where can I change that ? The text property will only changes the text in the table header, not the column one.
af:messages
I can change the error message alrigth, but not the "title", that is: "Error", "Warn" and such. Where is the bundle for that? Is it even customisable?
Entity object validation errors
I can specify any message in the entity object configuration, or a resource bundle key and change the Bundle class that get generated. However this solution implies that the model layer knows the user's locale which I highly dislike. Therefore, I developped something else:
1. I define a bundle key in the entity object validator messages
2. I add a before render phase listener
3. The listener inspects all messages registered in the context and recognize the bundle keys set by the entity objects validators
4. Overwrite the key with the corresponding message
Is there a more elegant way to do it?
Regards,
Simon Lessard
Message was edited by:
Simon LessardHi Simon,
Translation in ADF Faces are based on view locale.
For example, please try to change your browser's locale.
For IE: Tools|Internet options... -> Languages -> Add another languages and move it to the top of language list.
Regards,
Jun -
Hi there i have 2 question i do not understand after ready the beginners turbs on sun.
firs 1 is how to set the path. i know how to get to environment variables on xp. but what do i put at value and at variable. and do i put it at system or at user.
i know that i need to put the path ( c:\j2sdk1.4.2\bin ) there. do i need to fill that in at value. if yes what do i fill in at the variable.
That was the first question the second 1 is about setting path
I got this error and found this description
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp
If you receive this error, java cannot find your bytecode file, HelloWorldApp.class.
One of the places java tries to find your bytecode file is your current directory. So, if your bytecode file is in C:\java, you should change your current directory to that. To change your directory, type the following command at the prompt and press Enter:
cd c:\java
The prompt should change to C:\java>. If you enter dir at the prompt, you should see your .java and .class files. Now enter java HelloWorldApp again.
If you still have problems, you might have to change your CLASSPATH variable. To see if this is necessary, try "clobbering" the classpath with the following command:
set CLASSPATH=
but my question is where do i put set CLASSPATH and what do i put after the = to get it workafter CLASSPATH= you write C:\java;C:\whatevere\other\dir\where\your\classes\are;.
notiece that . (dot), that means "current directory", that means java is looking for classes also in the directory where you called it from.
and furthermore, as you see, in MS systems (such as Windows*) you have to separate different paths with ';' not with ':' as you would want to normaly separate them.
good luck. -
ATV worked great one small glitch Question
ATV update is great, however got one small glitch ?
I have ripped a couple of movies prior to the update and they worked fine they still seem to work, however on the movie list one movie appears like 20-30 times. All of the other movies dont have a problem. Anyone know how I can eliminate the movie being repeated??? Thanks
Oh it only shows up once on my computer.
KenImplementation:
As per my knowledge implementation is first time the company is going to use (implement or install) SAP.SAP R/3 with all the module are which are the module business need depends on the business requirement.
Normally the phases in a SAP R3 implementation project would be the following:
Project Preparation
Business Blueprint
Realization
Final Preparation
Go Live (Pre go live ,Post go live)
Upgrade :
Version upgrade
Company is using sap already they are going for higher version of Sap example R/3 4.7 to ECC5.0/ECC6.0(R/3 Version upgrade)
Other upgrades
Database upgrade or Migration
One data base to another database(Example SQL to ORACLE)(Oracle 8.0 to 10G)
OS Upgrade or Migration
One OS to another OS(Windows to UNIX)
Sap Module Upgrade
New sap module addition to existing R/3 which is not implemented later business improvement or going to some other new additional business (like PP,TPVS,HR)
FMCG to Hotels,Packing division(SAP Company they are going to use the same server and R/3)
Additional Sap Component
Company may need additional SAP component like BW,CRM,SRM,APO this is also part of upgrade but this is not Full life cycle .
Full lifecycle upgrade
SAP R/3 version upgrade with all existing sap module with sap component.
Basis:
Every phase basis involvement must be there. -
HI I just would like to know if I'm right
I want a tag that writes in jsp a link for an alias.
The parameter is the key of a hashtable and
the return value is the link
Is it correct just to write this simple line?
Thanks Starki
* Method called at start of tag.
* @return SKIP_BODY
public int doStartTag() throws JspException
try
JspWriter out = pageContext.getOut();
out.write(LinkPool.getLink(linkAlias));
catch(Exception exception)
throw new JspException("Could not save body");
return SKIP_BODY;
}Can someone give me a small hint?
Thanks a lot! -
Small installation question..
I am currently researching whether Sharepoint would be the correct platform for my company. But I get overwhelm with the hardware requirements.
I will need Sharepoint on premise license, since majority of the information will be sensitive in nature. My company consists of 20 employees at 1 location. currently we only have 3 servers (domain controller, exchange server and dedicated server
for a DMS). The thought was to replace the existing DMS with Sharepoint's record retention module.
Are there simplified Sharepoint system requirements for smaller installations?Yes, you can do a single server installation of SharePoint and SQL Server on the same system, Microsoft outlines it here:
http://technet.microsoft.com/en-us/library/cc262485(v=office.15).aspx#hwforwebserver
Trevor Seward
Follow or contact me at...
  
This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.
Maybe you are looking for
-
Report for sales target & Production target
Report for sales target & Production target which should include the following fields Sales Target Revised Sales Target Production Target Revised Production Target Action Need to be taken
-
How do I create a URL from ID to PDF to Entourage?
G5 Mac. Tiger. ID CS 4. I'm 2/3 of the way there. The last 1/3 id the hassle. I type out a URL in ID 4 and follow this path: Type > Hyperlinks & Cross-References > New Hyperlink from URL. Do Save as... , and have a usable URL link that does not work
-
Designer 6.0 Repository Reports and PL/SQL Error ORA 6505
Trying to run some Repository reports give error REP-1401 'cf_desc_textformula'. Fatal PL/SQL error occurred. ORA-06505: PL/SQL: variable requires more than 32767 bytes of contiguous memory Occurs at e.g. ckentdef Seems to be that Reports has Problem
-
No of elements in a logical level.
Hi I am very much confused with the following one. How do we know that there should be some "n" number of elements in one logical level? "No of elements at this level......." ? Thanks&Regards Suresh.
-
Immediately after an upgrade Firefox beginning throwing my Mac into Work Offline mode. Apparently, this is done anytime my connection blips out. I have tried a work-around, but to no avail. The computer is thrown into Work Offline when I daily turn o