The great thing about Java is that it was designed to have a similar syntax as C++ and Arduino will gladly compile C++. So if you're familiar with Java this should be pretty easy for you.
check out This Tutorial
As for your example...
Much like Java, it is best practice to put C++ classes in their own files, but it is not required. If you use Java you are used to "importing" modules and classes into the class you are creating. Similarly C++ imports header files (behind the scenes it is much different, but functionally the same).
To do this first you would create a header file. This is just a text file with the extension ".h" or ".hpp" intead of ".txt" - traditionally .h is used only for c files and .hpp would be for c++. The header file will include the class and method prototypes.
Before I get to your example, as a side note:
Your example using the "sketch" variable is somewhat confusing because a sketch is just what the world of Arduino calls a program and it would not be used as variable.
"DoClass.hpp"
class DoClass {
int var;
public:
DoClass(int var);
int getVar();
};
"DoClass.cpp"
#include "DoClass.hpp"
DoClass::DoClass(int variable){
var = variable
}
int DoClass::getVar(){
return var;
}
The "::" means "member of" so the getVar() is a method of DoClass.
These files should be saved in your sketch folder. If you are creating a class that will be reused you can place it in ../sketches/libraries/.
#include "DoClass.hpp"
setup(){
...
}
DoClass myClass(5); // creates class
int testVal;
loop(){
...
testVal = myClass.getVar();
}