Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.class files

 
Prahlad Joshi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abstract class a
{
abstract int print(String s);
public void methodA()
{
System.out.println("in method A of abstract class");
}


}
class A extends a
{
public int print(String s)
{
System.out.println("printing"+s);
return 1;
}
public void methodA()
{
super.methodA();
}
}
abstract class b
{
abstract void methodB();
public void caller()
{
a object=new A();
object.methodA();
}

}


class B extends b
{
public void methodB()
{
System.out.println("oveerinding or implementing abstract class'm ethodB");
}
public void caller()
{
super.caller();
}
}
public static void main(String args[])
{
B object =new B();
object.caller();
}
I couldn't understand why the above code is generating the following error
Exception in thread "main" java.lang.NoClassDefFoundError: b (wrong name: B)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at NewClass.main(NewClass.java:52)
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you running this on a Windows machine? Windows file systems are case-insensitive by default, so "B.class" and "b.class" are the same file--but your program requires that those two files be distinct since they contain different classes.

One way to overcome this problem is to generate the two class files one by one and put them into a .jar file, which will preserve the case distinction. Another solution is to put the two classes in different packages. But ultimately, this example illustrates why you should generally follow the naming convention of using UpperCase for type names, and avoid having type identifiers that differ only in case.
[ November 01, 2007: Message edited by: Kelvin Lim ]
 
Prahlad Joshi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your quick and complete explanation Kelvin(ya i am using windows).It cleared all my doubts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic