#Difference between declaring a class and creating an object of a class in different files

6 messages · Page 1 of 1 (latest)

strong drum
#

Let's say you have 2 classes: one is named DriveWithXBoxCommand and the other is DrivetrainSubsystem. Both of them are in their own separate file. The DrivetrainSubsystem class/file has a public method called arcadeDrive. In the DriveWithXBoxCommand class/file, you declare the variable drivetrainSubsystem as public final DrivetrainSubsystem drivetrainSubsystem and call arcadeDrive using drivetrainSubsystem.arcadeDrive(). What happens if you create an object of the DrivetrainSubsystem class like public DrivetrainSubsystem drivetrainSubsystem = new DrivetrainSubsystem() in the DrivetrainSubsystem file and then try calling the arcadeDrive method using drivetrainSubsystem.arcadeDrive()? Will it still work? What's the difference between these two?

cosmic charmBOT
#

This post has been reserved for your question.

Hey @strong drum! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

strong drum
#

Difference between declaring a class and creating an object of a class in different files

hallow drift
#

it will still work

#

what you are doing is creating an instance of a class when you use new ...