Intro to FRC Programming - Romi
  • INTRODUCTION
    • Overview
    • Important Links
  • 💽Setup
    • Setting up the Romi's Software
    • Downloading Essential Tools
    • APCS vs FRC
  • How To Code in VSC
    • VSC- Intro
    • A Tour Through VSC
    • Creating a Regular Java Project
  • Intro to Java
    • What is Java?
    • Beginning Steps
    • 🟩Fundimentals of Java
      • Variables
      • Operations
      • Methods
      • Comments
      • If Statements and Conditions
      • Boolean Zen
      • Loops
      • Challenge- Create a Box House
    • 🟨Advanced Concepts
      • Objects
      • Scanners
      • Null Objects
      • Arrays
      • Errors
      • For-Each Loops
    • 🟥Object Oriented Programming
      • Basics of OOP
      • Instance Classes
      • Static Classes
  • 🕑Romi Curriculum- Timed Base
    • Romi Curriculum- Introduction
    • Creating a WPILIB Project
    • Running Your Code
    • The Robot Class
    • Subsystems
      • RomiDrivetrain
    • Cool stuff i will rename this category later
      • Spark Motors
      • PIDs
      • External Controllers
      • Encoders
  • 🖥️Romi Curriculum- Command Based
    • Command Based Code
    • RobotContainer
    • Commands
    • CommandScheduler
  • UNRELATED IMPORTANT CODING KNOWLEDGE
    • Constants
  • SAMPLE CODE
    • Tank Drive Example
      • RobotContainer
      • TankDriveSubsystem
      • MoveRobotCommand
    • Worktop Systems Sample Java Code
      • Belt Elevator Sample Code
      • Rotating Arm Sample Code
Powered by GitBook
On this page
  • Making a static class
  • Calling static classes
  1. Intro to Java
  2. Object Oriented Programming

Static Classes

The other type of class is a static class, these methods can't be created into objects. Instead their methods and fields are called directly from the class. Along with this, since they don't come in the form of objects, they don't have constructors.


Making a static class

When making a static class, you have to add the static identifier to both the class declaration, methods, and all fields (not variables that are in a method).

Here is an example of a static class:

public static class ExampleStaticClass{
    //feilds
    public static int x = 3;
    public static int y = 4;
    
    //methods
    public static int add1ToY(){
        this.y++;
        return this.y
    }
    public static int add1ToX(){
        this.x++;
        return this.x;
    }
}

Calling static classes

When it comes to calling methods or fields from a static, you don't create a method like in an instance class, you instead call it directly from the class by the name.

Here is an example using the static class ExampleStaticClass:

int val = ExampleStaticClass.y; //get int from y

//add 1 to y and return new value
int newVal = ExampleStaticClass.add1ToY();
System.out.println("Difference: " + (newVal - val) );

PreviousInstance ClassesNextRomi Curriculum- Introduction

Last updated 7 months ago

🟥