GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Objects and Classes

Kevin Benitez Englisch

Inhalt der Mindmap

Objects and Classes

  1. Every object can have fields(attributes) and/or methods(actions).

  2. Class: Blueprint for the object

    • Needs: Class name, fields, methods
      • Class declaration: must use keyword class
        • {} are used after class for the body
        • Every class must have at least one constructor
          • Looks like a method
          • Does not have a return value
          • Must have same name as class
          • constructorName (listofArguments) { [constructor body] }
            • Used to initialize fields in object
              • new Employee(20, 90000.00);
            • public className (int arg1, method arg 2)
    • Class definition must be saved in file with same name as class name with .java
  3. Fields are variables for the class in question

    • Fields can refer to another object as well
      • Follow camel naming convention (add,dataType,etc.)
  4. Methods define actions of a object

    • returnType methodName (listofArguments)
      • double getSalary() returns a double with no accepting arguments
      • int add(int a, int b) accepts two arguments and adds them
    • Main provides entry point to an application
      • One of the classes in an application needs to have a main method
        • public static void main(String[] args)
        • Can pass arguments to main when using java to run a class
          • java className arg1 arg2 arg3...
  5. Assign created object to an object reference variable

    • objectReference.methodName
    • objectReference.fieldName
    • When reference variable does not have value, it has a null value
      • If (book == null){ book = new Book(); }

Informationen

Beschreibung
Mindmap am Objects and Classes, erstellt von Kevin Benitez am 20/05/2021.
Erstellt von
Kevin Benitez
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck