• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is the error in it

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package testpackage;
import other.*;
class Test
{
public static void main(String args[])
{
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello)+"");
System.out.print((other.Other.hello == hello)+"");
System.out.print((hello == ("Hel"+"lo")) +"");
System.out.print((hello == ("Hel"+lo))+"");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello";}
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raji:
Did you try to compile this code? What error messages does the compiler display to you? Do you have a package called other in your current directory? What is that package supposed to
contain?
What is the expected outcome of this program?
Please try to give as much relevant information as possible. Always try to compile the code first and if you don't understand the compiler error messages, then post your code and the messages you get as well.
 
Raji Addepalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi iam getting compiler error as
C:\Java\Test7.java:2 ackage other does not exist
import other.*;
C:\Java\Test7.java: 8 : cannot resolve symbol
symbol : class other
location: package testPackage
System.out.print((testPackage.Other.hello)+"")
C:\Java\Test7.java: 9 : cannot resolve symbol
symbol : class other
location: package other
System.out.print((other.Other.hello == hello)+"")
3 errors
 
Raji Addepalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops funny symbol came inbetween
that line is
C:\Java\Test7.java: 2 : Package other does not exist.
[ January 15, 2002: Message edited by: Raji Addepalli ]
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Define the Other class in package other
i.e
package other;
class Other{}
Try to compile and see this
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arathi is correct.
You need to have a package other, containing a class Other, in your current directory ( whereever the program you are trying to compile is ).
This line from the program should be your clue to what the other.Other class should be defined as.
System.out.print((other.Other.hello == hello)+"");
There is no instance of that class created, but this code is refering to a variable named other.Other.hello and comparing it with another variable named hello. The second variable is of type String. So I imagine, the other.Other class needs to have a public static String named hello, since the other.Other is in a separate package and your program is in testPackage package.
Hope this helps
 
Arathi Rajashekar
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shivaji Marathe:
Arathi is correct.
You need to have a package other, containing a class Other, in your current directory ( whereever the program you are trying to compile is ).
This line from the program should be your clue to what the other.Other class should be defined as.
System.out.print((other.Other.hello == hello)+"");
There is no instance of that class created, but this code is refering to a variable named other.Other.hello and comparing it with another variable named hello. The second variable is of type String. So I imagine, the other.Other class needs to have a public static String named hello, since the other.Other is in a separate package and your program is in testPackage package.
Hope this helps


Slight correction Shivaji.
The class other should be declared public. Only then it can be accessible by Test class. Am I correct
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arathi :
Correct again. I just thought that that would be obvious.
Thanks
 
Raji Addepalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic