Friday, 15 July 2011

java, having a hard getting my print class to print my other class information, please help these are my codes -



java, having a hard getting my print class to print my other class information, please help these are my codes -

// first class public class firstproject{ int first_number; public firstproject(){ first_number = 0; } public firstproject(int fn){ first_number = fn; } public void print(){ system.out.println("first number = " + first_number); system.out.println(); }

}

//second class in separate file // maintain getting error on class saying cannot find . in p1.print();

public class testprogram { public static void main(string[] args){ firstproject p1 = new firstproject(10); p1.print(); system.out.println(); }

java case-sensitive:

p1.print();

but improve change

public void print(){ -> public void print(){

since methods should not start capital letter, according conventions.

java

No comments:

Post a Comment