Hi guys ,
i am a to programming and have to do little code as an excercise, but got little confuse about constructors and objects while compiling my programm.

forexample
i created an object of a class called AsciiImage;
in the Main class
public class AsciiReader{
public static void main(String [] args){
int height=0;
int width=0;
AsciiImage p = new AsciiImage(width, height);
}
and the Aciiimage class
public class AsciiImage{
int height;
int width;
contstructor
public AsciiImage(int height, int width){
this.width= width;
this height=height;

the only problem by compiling is this:
cannot find symbol class AsciiImage

can some body help me
thanks

public class AsciiImage{
int height;
int width;
//contstructor
public AsciiImage(int height, int width){
this.width= width;
this height=height;

the only problem by compiling is this:
cannot find symbol class AsciiImage

can some body help me
thanks

You dont give public to the constructor.So, your constructor should look like this:

AsciiImage(int height, int width)
{
this.width= width;
this.height=height;
}

Once you declared the class as public means, all the members (variables, and constructors and methods) are public, so you don't need to declare again constructor as public

Woah guys. Couple of incorrect postings here:
1. If you don't declare a constructor as public, its scope will be limited to the package in which it's declared. This may, or may not. be what you intend. If you want to call it from another package it MUST be declared public.
2. Declaring a class as public does NOT mean that its members are public. Their scope will be the classes' package unless declared otherwise.

ps: You can have 2 or more classes in 1 file, but only 1 can be declared public. because the file name must match the public classes' name.
If you think I'm wrong on any of these points, please check the Java language definition or try building a test case before flaming me - I'm only trying to help!

Sorry for the slight incorrection in my post, I stand corrected. Im facing my own dilema working within a package. Thats as far as my scope in java goes at the mo. Thread: Create & start threads with loop.

Hope you fixed you issue. :$

yeah!
I thin Jamescherill is right
because i was working on my little code AsciiReader which should have the main file code. AsciiReader.java ,,,,,,, the excutable one
and the AsciiImage.java which can is called from AsciiReader.
### the main class AsciiReader generates a onbject of the class AsciiImage.
so i definitely needed a constructor in my AsciiImage class
which as james said shouldnt be declared public.
i did't declare it public and it worked.
my problem was that the name i gave my AsciiImage didnt match the name i stored on my directory:::: tht was the reason i could'nt compile it
thnks guys

This article has been dead for over six months. Start a new discussion instead.