Results 1 to 2 of 2
Thread: inheritence questions
- 04-05-2010, 10:40 PM #1
inheritence questions
First
ThenJava Code:public abstract class PreSetter { public StringBuffer sourceFile = new StringBuffer("aa"); }
ThenJava Code:public class Main extends PreSetter { sourceFile.append("hello"); }
I thought that when using PreSetter class, i am crearing a new Object sourceFile, reference of which is accessed by Main, and assigned value "hello".Java Code:public class Arguments extends PreSetter { System.out.println(sourceFile); // blank. Why? }
Class Arguments later attempt to print out that reference, but it seems as if it is being "new"(ed) and assigned "aa" on access.
Can you help me understand this?
-
Your code doesn't compile so I'm not sure how you're calling things. You may want to post a small bit of code that compiles and runs and demonstrates your problem. e.g.,
Java Code:public class MacTest { public static void main(String[] args) { System.out.print("Arguments: "); new Arguments(); System.out.print("Arguments2: "); new Arguments2(); } } abstract class PreSetter { public StringBuffer sourceFile = new StringBuffer("aa"); } class Main extends PreSetter { Main() { sourceFile.append("hello"); } } class Arguments extends PreSetter { Arguments() { System.out.println(sourceFile); } }
Similar Threads
-
please explain multiple inheritence by an example lot of tutorial i checked but not
By javastuden in forum New To JavaReplies: 1Last Post: 02-08-2010, 01:57 PM -
Getting around inheritence
By nick2price in forum New To JavaReplies: 3Last Post: 01-18-2009, 06:48 AM -
How to get objects to interact without inheritence in separate classes?
By Fliz in forum New To JavaReplies: 1Last Post: 11-18-2008, 04:48 PM -
[SOLVED] Problem with code - inheritence
By yalla in forum New To JavaReplies: 1Last Post: 03-30-2008, 06:11 AM -
3 Questions
By hiranya in forum AWT / SwingReplies: 4Last Post: 11-14-2007, 04:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks