Accesing a method from another java file
i had written two java files, firstcalss1.java and moreclass1.java. And i tried to access a method from firstclass1.java .. the code is below...
firstclass1.java
--
import java.io.*;
public class firstclass1
{
public firstclass1()
{
}
public void printname()
{
System.out.println("This is the first class, name is xxxxxx ");
}
}
moreclass1.java
--
import java.io.*;
class moreclass1
{
public static void main(String args[])
{
firstclass1 ob1 = new firstclass1();
ob1.printname();
System.out.println(" This is the main class .....");
System.out.println("hai ");
}
}
But i got an error that cannot resolve the symbol firstclass1..
how can i solve this..
the below is the full error....... before this i compied the firstclass1.java using the command javac firstclass1.java.. and here i am using the fedora as operating system..
moreclass1.java:9: cannot resolve symbol
symbol : class firstclass1
location: class moreclass1
firstclass1 ob1 = new firstclass1();
^
moreclass1.java:9: cannot resolve symbol
symbol : class firstclass1
location: class moreclass1
firstclass1 ob1 = new firstclass1();
^
2 errors
Hi ,
I think this will help you ,
Lets suppose you have two classes ,
1>- Test17.java
2>-Test18.java
Now watch the Test17.java code carefully,,,,
import java.io.*;
public class Test17
{
public Test17()
{
}
public void printname()
{
System.out.println("This is the first class, name is xxxxxx ");
}
}
Here the Test18.java code ,,,,
import java.io.*;
class Test18
{
public static void main(String args[])
{
Test17 ob1 = new Test17();
ob1.printname();
System.out.println(" This is the main class .....");
System.out.println("hai ");
}
}
I think this will help you ,
Thanks ,
Sb.