Note that there are some explanatory texts on larger screens.

plurals
  1. POgot an error message while compiling a java class that contains object of other type
    text
    copied!<p>I'm new to java programming language. I made a package name pack. Which contains two java classes A.java and B.java. I'm using jdk1.5 and tomcat. I want to create an object of A type and place it in B.java. Below is how i am trying to do this but getting two error messages.</p> <p><strong>package pack;</strong></p> <p><strong>A.java</strong></p> <pre><code>public class A { private String str; public A(){} //constructor method public void setName(String str){ this.str = str; } public String getName(){ return str; } } </code></pre> <p><strong>B.java</strong></p> <pre><code>public class B { private String temp; public B(){} //constructor method public String getTemp(){ A a = new A(); //creating an object of A type temp = a.getName(); //assigning the value of getName method to temp variable return temp; // returning temp variable } } </code></pre> <p>Jdk1.5, tomcat and package pack are in the below directory</p> <p><strong>D:\java></strong></p> <p>Below are the steps that i am taking to compile A.java and B.java</p> <p><strong>compiling A.java</strong></p> <pre><code>D:\&gt;cd java D:\Java&gt;cd pack D:\Java\pack&gt;set path=D:\java\jdk1.5\bin (**setting up path of jdk1.5**) D:\Java\pack&gt;javac A.java (**Compiling A.java. Compiled it successfully**) </code></pre> <p><strong>compiling B.java</strong></p> <pre><code>D:\Java\pack&gt;javac A.java (**Compiling B.java. Unable to compile**) **(Error Message is below)** D:\Java\pack&gt;javac B.java B.java:9: cannot find symbol symbol : class A location: class pack.B A a = new A(); //creating an object of A type ^ B.java:9: cannot find symbol symbol : class A location: class pack.B A a = new A(); //creating an object of A type ^ 2 errors </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload