Think about it: consider an physical invoice.
Customer name
Customer address
Date
Invoice numner
Items:
12 Widgets $10.00 $120.00
5 Thingumies $1.50 $7.50
Total: $127.50
When you create that, you enter the customer info, allocate an invoice number, set the date - and then start adding items to the invoice - it's the only sensible way to do it!
The electronic version would be three tables:
Customers:
ID
Name
Address
Invoices:
ID
CustomerID
Number
Date
InvoiceItems:
ID
InvoiceID
Count
Description
UnitCost
And the CustomerID and InvoiceID would be Foreign keys.
You can't create an Invoice if you don't have a Customer set up (or you don;t know where to send it!) and you can't create an InvoiceItem unless you have an Invoice to allocate it to!
So you create Customers first, so you can use the CustomerId foreign key in the Invoice, and the Invoice before the InvoiceItem so you can use the InvoiceID foreign key.
Your system is the same: Your Teachers and Subjects will be created before the Classes can be assigned, then the Students can be created and added to the system using the existing info.
Foreign keys are very useful - they help preserve data integrity by making sure you can't delete a Teacher if they are still supposed to have Classes...
But ... why does your Class reference a Student, and your Student reference a Class? Wouldn't a Student have more than one class?