I am new to programming and I don't know how to make interfaces. My code is :

public class CarsDescription {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    interface Domestic {}
    interface Import {}
    interface Japanese extends Import {}
    interface German extends Import {}
    interface Detroit extends Domestic {}
    interface SpringHill extends Domestic {}
    interface Vehicle {}
    interface Automobile extends Vehicle {}
    interface LargeAutomobile extends Vehicle {}
    interface Sedan extends Automobile {}
    interface Van extends LargeAutomobile {}
    interface Truck extends LargeAutomobile {}
    interface Compact extends Automobile {}
    interface SportsUtilityVehicle extends Truck, Van {}
   
    class SaturnSL1 implements SpringHill, Sedan {}
    class HondaCivic implements Japanese, Compact {}
    class MercedesC230 implements German, Sedan {}
    class ChevyS10 implements Detroit, Truck {}
class SubaruOutback implements Japanese, SportsUtilityVehicle {}
    }
}

Interfaces and classes must be outside of method bodies.

public class CarsDescription {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    }

    interface Domestic {}
    interface Import {}
    interface Japanese extends Import {}
    interface German extends Import {}
    interface Detroit extends Domestic {}
    interface SpringHill extends Domestic {}
    interface Vehicle {}
    interface Automobile extends Vehicle {}
    interface LargeAutomobile extends Vehicle {}
    interface Sedan extends Automobile {}
    interface Van extends LargeAutomobile {}
    interface Truck extends LargeAutomobile {}
    interface Compact extends Automobile {}
    interface SportsUtilityVehicle extends Truck, Van {}
   
    class SaturnSL1 implements SpringHill, Sedan {}
    class HondaCivic implements Japanese, Compact {}
    class MercedesC230 implements German, Sedan {}
    class ChevyS10 implements Detroit, Truck {}
    class SubaruOutback implements Japanese, SportsUtilityVehicle {}
}

There is something to be said for putting each and every class and interface into its own file. But that is not required.

I'm not sure I see what it is you're trying to do with these interfaces. What does it buy you to implement (sorry) these categories as interfaces, and not, say, as booleans or as enums or named constants?

I can't think of any method signatures that would be required of a Japanese auto and not a German one....

That is quite true: It's one crazy mass of empty classes and marker interfaces. I have no idea what vishal1949's next move will be. But it's sure to be interesting. ;)

I assume he's just trying to get the hang of extending and implementing interfaces and classes, in a course he's following.

This is just the beginning of my assignment. Next I have to add a declaration to the Vehicle interface( int getWeightinPounds) and make a parking garage class that can hold 20 vehicles or 25000 pounds. I am going to have to use charstack(); push(); and pop(); for that.

Could someone tell me whether the following would compile. I got all of them done but am not sure if i am right.

public class VehicleAssignment {
interface Domestic {}
interface Import {}
interface Japanese extends Import {}
interface German extends Import {}
interface Detroit extends Domestic {}
interface SpringHill extends Domestic {}
interface Vehicle {}
interface Automobile extends Vehicle {}
interface LargeAutomobile extends Vehicle {}
interface Sedan extends Automobile {}
interface Van extends LargeAutomobile {}
interface Truck extends LargeAutomobile {}
interface Compact extends Automobile {}
interface SportsUtilityVehicle extends Truck, Van {}
    
class SaturnSL1 implements SpringHill, Sedan {}
class HondaCivic implements Japanese, Compact {}
class MercedesC230 implements German, Sedan {}
class ChevyS10 implements Detroit, Truck {}
class SubaruOutback implements Japanese, SportsUtilityVehicle {}

SaturnSL1 sl = new SaturnSL1();     // This is the part going all the way down
HondaCivic hc = new HondaCivic();
Japanese jp = new Japanese();
German gr = new MercedesC230();
ChevyS10 cs = new Truck();
SubaruOutback sb = new SubaruOutback();
Domestic dm = sl;
dm = hc;
dm = (Domestic) hc;
dm = cs;
dm = (Domestic) cs;
Import im = sb;
gr = im;
gr = (German) im;
jp = im;
jp = (German) im;
jp = (Japanese) im;
Automobile a = cs;
a = hc; // this is the end

I am marking this solved since you have now created another new thread to continue this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.