A Notes:
1. You have been using classes and objects without knowing the terms. That's because Java provides many "built-in" classes for programmers. For instance:
String class:
Is "abc" an object? Do you know String x = "abc"; and String x = new String("abc"); are the same?
What can you do with an object?
x.length(), x.charAt(0), x.toUpplercase(); x.substring(0,2)
all methods are called on object x, and each method "does something" to the object x; here, "does something" is an action, x is the subject of that action
if String y ="defg"; all above methods will return different results, hence the different objects can have the same actions such as substring, but the results may be specific to that object.
sometimes, a method can take another object as a parameter, as in str1.compareTo(str2), it is a method called on object str1, while object str2 is the parameter.
Scanner class:
Scanner in = new Scanner (System.in);
in is an "object"
in.nextInt() is a method called on the object in, it reads an int from the keyboard
Scanner file = new Scanner (new FileReader("data/ninetynine.txt")); is another object;
file.nextInt() is a method called object file, it reads an int from a file
2. The concept of instances
each object such as "abc", "defg", in, file, is also called an instance of the class. An object and an instance are the same thing.
each variable in an object is an instance variable, String and Scanner each has only one instance variable, while the Student class has many
each method called on the object is an instance method, such as substring(), toUppercase(), nextInt() etc
different objects will have different values of the same instance variable, for example student1.studentName="Allen", student2.studentName="John"
when different objects call the same instance method, the returned values are different, for example, "Hello".substring(2, 3)="l", "Sprint".substring(2,3)="r"
B. Exercise:
What could be some instance methods of the Student class? For instance, assume you want to check if a student qualifies to join a club.
How would an object of the Student class call the method? What is the result of calling the method?
What could be some instance methods of the Fish class? Tree class?
Create a class named "CreditCard", what are the instance variables and instance methods?
Create a class named "TicTacToe", what might be the instance variables? what might be the instance methods?
Try to code "CreditCard" class and "TicTacToe" class in repl.it and include your link below