Java is not printing in a different class that doesn't contain main -



Java is not printing in a different class that doesn't contain main -

i've been experimenting oop code. started taking stanford's cs106a, , since uses acm library, syntax might little off.

so, here javadoc, http://cs.stanford.edu/people/eroberts/jtf/javadoc/student/acm/program/consoleprogram.html

i'm using 2 classes named "itunes" , "test". "test" class contains "main", here uses "run" method kind of analogous "main" method.

first class, "test"

import acm.program.consoleprogram; public class test extends consoleprogram{ public void run(){ itunes song1=new itunes("acdc",1991); song1.displaysong(); } }

second class, "itunes"

import acm.program.consoleprogram; public class itunes extends consoleprogram { private static string name; private static int year; public itunes(string name1,int year1){ name = name1; year = year1; } public void displaysong(){ println(name); println(year); } }

it compiles without errors nil appears on console. blank. if homecoming values run , display them within run, works.any thought why happening?

also if wanted homecoming both string name , int year single function, can that? in case homecoming type?

your itunes class extending consoleprogram well.

that means, moment create instance of class, second console created, output of class goes to.

for reason, seeing output if return values (they printed first consoleprogram, working first console viewing.)

you should either switch console view (assuming eclipse) or don't create sec consoleprogram within main program. seems regular class (without extending consoleprogram) serve needs.

also if wanted homecoming both string name , int year single function, can that? in case homecoming type?

there various options:

you homecoming list<object> specific position each returned value. you utilize private properties (and getters) in itunes class, ans access result after processing input (itunes.getname(); itunes.getyear();) you create own result object, containing required homecoming parameters. and many more ...

java

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -