|
-
Aug 11th, 2001, 12:35 PM
#1
Thread Starter
Hyperactive Member
:confused: Class Help
I have a program that looks like:
public class tester
{
public VPixel asdf;
...
}
class VPixel
{
public VPigment r;
public VPigment g;
public VPigment b;
...
}
class VPigment
{
...
}
but it gives me a compile error when i try to use VPixel as a variable in the tester class. Any ideas?
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Aug 11th, 2001, 12:39 PM
#2
Member
You cannot include more than one class in a file. Otherwise JavaC gets confused and gives an error.
-
Aug 11th, 2001, 12:41 PM
#3
Thread Starter
Hyperactive Member
so how would i reference a class from another file?
"There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein
If you are programming in Java use www.NetBeans.org
-
Aug 11th, 2001, 02:36 PM
#4
Dazed Member
Im not too sure about having seperate classes in one file,
but you can have nested classes or classes local to a method block "Local class" within one file.
public class NestedTest{
public static void main(String[] main){
Nest n = new Nest(100,500);
n.z();
}
static class Nest{
static int i;
int x;
Nest(int i, int x){
this.i = i;
this.x = x;
}
// non static variable can access bolth field members
// static void z(){ then you can only access int i.
void z(){
System.out.println(" The value of i is " + i);
System.out.println(" The value of x is " + x);
}
}
}
-
Aug 11th, 2001, 03:29 PM
#5
Dazed Member
Classes declared without a package statement fall into the defualt package. Then all you have to do is reference them accordingly. If the package statement is not used you have to reference a class with it's full package name. For instance.
Code:
import java.util.Vector;
//or
import java.util.*;
public class vectorTest{
public static void main(String[] args){
Vector v = new Vector();
// if all of the important statements were excluded you
//would have to reference Vector as such.
java.util.Vector v = new java.util.Vector();
}
}
-
Aug 11th, 2001, 03:45 PM
#6
Originally posted by Dilenger4
Im not too sure about having seperate classes in one file
The answer to that is Yes, you can have more than one class in one file, but only 1 public class. I believe that separate .class files are made for each class.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Aug 11th, 2001, 04:02 PM
#7
Member
But you cannot create a private class. So any other scope would work.
-
Aug 11th, 2001, 04:33 PM
#8
Dazed Member
-
Aug 13th, 2001, 01:42 PM
#9
crptcblade is correct.
CaptainPinko,
Your posted code seems fine. How are you trying to "use VPixel as a variable in the tester class"? Can you post the problem code?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|