Results 1 to 8 of 8
- 03-14-2009, 09:24 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
-
It's impossible to know how to answer your question without more information. A great resource that has helped me and will probably help you is an article entitled How To Ask Questions The Smart Way. It will tell you how to formulate your questions so that the folks here will be better able to answer them.
I suspect though given the names of your classes that laptop extends computer, but again it's impossible to know without more information. If this is the case, then you most definitely do not want computer to use any of laptops methods. If this answer doesn't help you, then please read the link above and provide us with more information. The link will tell you what we need to see.
- 03-14-2009, 09:58 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
Term Class
Java Code:public class Term { public int upper; //polinomun ussunu tanimladim public int exponent; //polinomun katsayisi public Term() //constructor { exponent=0; } public void setUpper(int upper) { this.upper=upper; } public void setExponent(int exponent) { this.exponent=exponent; } public int getUpper() { return this.upper; } public int getExponent() { return this.exponent; } public Term(int upper,int exponent) { setUpper(upper); setExponent(exponent); } public String toString() { return String.format( "#Polynomial# Exponent : %s, Upper : %s",this.exponent,this.upper); } }above the classes are.Java Code:public class Polynomial { ArrayList<Term> poli=new ArrayList<Term>(); Term term=new Term(); public int birinci; public int ikinci; public int ucuncu; public int getBirinci() { return this.birinci; } public int getIkinci() { return this.ikinci; } public int getUcuncu() { return this.ucuncu; } }
I want to display in the console polynomial's exponent (exponent is a variable of term)
-
which Term? The Term variable? or the Term objects within the arraylist? Either way, the Polynomial object can have a toString method that calls either the term's toString method or using a StringBuilder, builds a String by iterating through the items in the poli ArrayList.
- 03-15-2009, 03:56 AM #5
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
That depends of the task you want to cope. If you need to init var during the whole program activity time you may use static variable...
So we have class A and B... We have var in A and want to access var from B to init A... so we must declare var in B as public to make it accessable from A. Or we must declare var as protected... You need to know more of modificators in Java
First describe your problem in a more specific way :)
- 03-15-2009, 02:20 PM #6
Member
- Join Date
- Mar 2009
- Posts
- 10
- Rep Power
- 0
ok i get it thanks..
- 03-15-2009, 04:34 PM #7
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
By the way, it's generally a bad idea to make all member variables public.
- 03-16-2009, 07:19 AM #8
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
Similar Threads
-
Calling a variable from a different java class
By jdiesel in forum New To JavaReplies: 4Last Post: 01-09-2009, 01:12 AM -
Interface variable to class
By zill in forum Advanced JavaReplies: 6Last Post: 10-11-2008, 03:29 AM -
Which class and variable to choose?
By kian_hong2000 in forum New To JavaReplies: 8Last Post: 08-27-2008, 07:06 AM -
Object class's equals() method behavior????
By skyineyes in forum New To JavaReplies: 4Last Post: 07-19-2008, 11:58 PM -
Public class variable
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 09:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks