Application written in single file fires NullPointerException

Can't understand, i have problem with abstract class getOn method, if i split my classes to different files and declare them as public, like that

package test.local;

abstract public class Passenger {

public void getOn(Transport transport) {

transport.takePassenger(Passenger.this);

}

}

package test.local;

public class Dog extends Passenger {

}

everything works fine, i can pass Passenger.this to getOn method, but if i write whole application in single file like that

import java.util.List;

interface Transport {

public void takePassenger(Passenger passenger);

}

class Bus implements Transport {

private List passengers;

public void takePassenger(Passenger passenger) {

passengers.add(passenger);

}

public List getPassenger() {

return passengers;

}

}

abstract class Passenger {

public void getOn(Transport transport) {

transport.takePassenger(Passenger.this);

}

}

class Dog extends Passenger...

Read More »

By: StackOverFlow - Thursday, 8 November

Related Posts