Below you will find a program I've been working on. Rather than using System.out.print("----"); in Comp1, Comp2, and Comp3.
I would like to access prt(b) in class Root
The way the program is now works fine. What can I do in Comp1, Comp2, and Comp3 to access prt(b)?? prt is public..right?
I tried
String b = "Comp1"; prt(b); but I get an error about prt(b). I also tried x.prt(b); and that didn't work either.
class Comp1{
Comp1() {
System.out.print("Comp1");
}
}
class Comp2 {
Comp2() {
System.out.print("Comp2");
}
}
class Comp3 {
Comp3() {
System.out.print("Comp3");
}
}
class Root {
public void prt(String a) {
System.out.println(a);
}
Root() {
String b = " In Root.";
prt(b);
}
}
public class Stem extends Root {
public static void main(String[] args){
Root x = new Root();
Comp1 comp1 = new Comp1();
Comp2 comp2 = new Comp2();
Comp3 comp3 = new Comp3();
}
}