javaclasscompilationacm-java-libraries

Program runs only at a specific pc


I had to write a program that creates credit card numbers. I wrote 3 classes, the main class, from where i can get the type and the length of the card (eg. Visa 15 digits), the luhn formula and one class where i create the card. From the main class i send the type and the length of the card to the last class. So i started the last class like this (its not all the code, only the first lines):

public class Cards extends Program {

private int[] x = new int[length];
private int[] k = new int[length];
private int length; 
private String type;

public Cards(int l, String name) {
    length = l;
    type = name;
}

which is clearly wrong (error at the compile) but the thing is that only my pc (where i also wrote these classes) can run it, without compile error and getting the correct results. I know where the problem is and the other 2 classes are correct but i want to know how is it possible to run at my pc without a problem.

Ps: I used acm package, my jdk is 1.8.0_31 and i wrote them on notepad++


Solution

  • I have the same version of the JDK, and class Card does not compile. You are probably executing against a previously compiled .class . Are you sure your code never was something like:

    public class Cards extends Program {
    
        private int[] x;
        private int[] k;
        private int length; 
        private String type;
    
        public Cards(int l, String name) {
            length = l;
            x = new int[length] ;
            k = new int[length] ;
            type = name;
        }
    }
    

    I bet it was! Try again after removing any file Cards.class in your PC.