Insert Record by Using Visualforce Page and Apex Class

In below example I’m inserting Account object record using Visualforce Page and Apex Class.

Visualforce Page:

<apex:page controller="CreateAccountController">
                <apex:inputfield value="{!acc.Name}"/>
                <apex:inputfield value="{!acc.Accountnumber}"/>
            <apex:commandbutton action="{!SaveMethod}" value="Save"/>

Apex Class:

public class CreateAccountController{
    public Account acc {get;set;}
    public CreateAccountController(){        
        acc = new Account();
    //Save Method 
    public PageReference SaveMethod(){
        Insert acc;
        return null;