GoConqr has a new look! Let us know what you think.

Mind map

Objects and Classes

Kevin Benitez English

Map content

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(); }

Information

Description
Mind Map on Objects and Classes, created by Kevin Benitez on 20/05/2021.
Created by
Kevin Benitez
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?