CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Packages

Packages
Related classes
Code more than one class

Two classes declared within the same file

import java.text.NumberFormat;

public class LineItem
{
    private Product product;
    private int quantity;
    private double total;
    .
    .
    .
}

class Product
{
    // body of Product class
}

The class files that are generated when the code is compiled

LineItem.class
Product.class

How to code more than one class per file

  • When you code two or more classes in the same file, you can only have one public class in the file, and that class should be declared first.
Previous | Code more than one class | Nested classes | Next