compiling java package classes. Cannot access Class. class file contains wrong class while working with packages -


i trying compile few files in package in java. package name library. please have @ following details.

this directory structure:

javalearning ---library ------parentclass.java ------childclass.java 

i tried compile in following way:

current directory: javalearning

javac library/parentclass.java   //this compilation works fine  javac library/childclass.java    //error on here 

the following parentclass.java:

package library; class parentclass{ ... } 

the following childclass.java:

package library; class childclass extends parentclass{ ... } 

the error follows:

cannot access parentclass bad class file: .\library\parentclass.class please remove or make sure appears in correct sub directory of classpath 

you've got casing issue:

class parentclass 

that's not same filename parentclass.class, nor same class you're trying use in childclass: class childclass extends parentclass.

java classnames case-sensitive, windows filenames aren't. if class had been public, compiler have validated names matched - non-public classes, there's no requirement that.

the fact you've ended parentclass.class suggests @ some point declared parentclass, changed declared name , when recompiling, windows overwrote content of current file rather creating parentclass.class.

make sure declared class name exactly matches filename. may want delete class files before recompiling, out of confusing state.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -