|
||
|
||||
|
??? That makes no sense. If you want to reverse a string, you don't need two classes to do it. Simply have your first class reverse itself:
Java Code
public class ReverseString
{
String txt;
public ReverseString(String str)
{
this.txt = str;
}
public void doReverse()
{
txt= new StringBuilder(txt).reverse().toString();
}
public String toString()
{
return txt;
}
}
Java Code
public class Tester
{
public static void main(String[] args)
{
ReverseString a = new ReverseString("Test");
a.doReverse();
System.out.println("Test reversed is " + a);
a.doReverse();
System.out.println("Reversed again is " + a);
}
}
__________________
ASCII a question .. Get an ANSI Please surround your code with [highlight=Java]code goes here[/highlight]. |
|
||||
|
Oh, it's definately possible. The question is why would you want to do that? In essence, you're creating two different identical classes
Not too many uses I can think of for that.
__________________
ASCII a question .. Get an ANSI Please surround your code with [highlight=Java]code goes here[/highlight]. |
| The Following User Says Thank You to helloworld922 For This Useful Post: | ||
chronoz13 (01-09-2009) | ||
|
||||
|
i just want to try something hehehehe.. so its possible ?
how can i do that with this kind of problem?? can you please modify it please....... i want to solve this one...... |
|
||||
|
...
Copy paste, and change the class name. Like I said, not very useful. Java Code
public class ReverseString1
{
String txt;
public ReverseString(String str)
{
this.txt = str;
}
public static String reverseAnother(ReverseString1 string)
{
return newStringBuilder(string).reverse().toString();
}
public static String reverseAnother(ReverseString2 string)
{
return newStringBuilder(string).reverse().toString();
}
public void doReverse()
{
txt= new StringBuilder(txt).reverse().toString();
}
public String toString()
{
return txt;
}
}
Java Code
public class ReverseString2
{
String txt;
public ReverseString(String str)
{
this.txt = str;
}
public static String reverseAnother(ReverseString1 string)
{
return newStringBuilder(string).reverse().toString();
}
public static String reverseAnother(ReverseString2 string)
{
return newStringBuilder(string).reverse().toString();
}
public void doReverse()
{
txt= new StringBuilder(txt).reverse().toString();
}
public String toString()
{
return txt;
}
}
__________________
ASCII a question .. Get an ANSI Please surround your code with [highlight=Java]code goes here[/highlight]. |
| The Following User Says Thank You to helloworld922 For This Useful Post: | ||
chronoz13 (01-09-2009) | ||
|
||||
|
ahh so world.. it's possible but its not advisable? ryt?
ahh if thats the case ill be aware of these things... i'm just trying to mix up something... anyway tnx for the effort sir..!! i really appreciate it tnx alot again! |
|
||||
|
defining a class is for ONE specific task.
creating a class that can only be used by using another class FIRST doesnt make any sense we are creating something for such a specific purpose .. do i have a point here sir? if i am.. then ill take this as another knowledge for my career tnx sir! |
|
||||
|
Yes, design a class for a purpose. However, that purpose may have many functions (and uses). One of the key elements of Java is to not re-design something when it works great, especially if all you're doing is copying
![]() Here's how I design classes: 1. What do I want the class to do? 2. What are some (as close to all as possible, but not all) ways this class could be used? 3. How do I want to implement 1 & 2 (fields and methods)? Try to keep 1 as tight as possible, and expand 2. 3 is just to make it work. You will also reach many points where you will need to make compromises. In these cases, 2 and 3 change 2a. What are some (as close to all as possible, but not all) ways this class could be used? 2b. Which are more important, and which are less important? 3a. Which do I choose to (not to) implement? 3b. What should I optimize for?
__________________
ASCII a question .. Get an ANSI Please surround your code with [highlight=Java]code goes here[/highlight]. |
| The Following User Says Thank You to helloworld922 For This Useful Post: | ||
chronoz13 (02-09-2009) | ||
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] linking two different classes | John | Object Oriented Programming | 11 | 27-04-2009 07:57 PM |
| Computing Classes | tazjaime | What's Wrong With My Code? | 3 | 26-04-2009 06:18 PM |
| [SOLVED] using 2 classes | AZBOY2000 | Object Oriented Programming | 7 | 21-04-2009 11:55 AM |
| Connecting to Oracle from within Eclipse | kairamr | Java IDEs | 1 | 12-11-2008 09:16 PM |
| Help using Abstract classes with arrays | crazydeo | Collections and Generics | 2 | 10-06-2008 04:45 PM |
|
100 most searched terms
Search Cloud
|
| 2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html java 2d arraylist java actionlistener java addactionlistener java double format java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programmers forum java programming forum java programming forums java programming help java project ideas java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextarea font color jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream two dimensional arraylist java writing ipod apps |