tags:

views:

137

answers:

3

how will you define an object?

A: 

Object in programming language is just like an object in a real world. Think of "Object" in code as a "thing" when you are reading a book. "Object"/"thing" both have two things, properties and things they can do.

e.g book What property does book have? books have colors, weight, number of pages, etc.

e.g person. what property does a person have? tallness, weight, etc.. and what can they do? they can do talking, walking, writing, etc.

David Gao
A: 

You define an object using what is typically called a class (in any OO language I've used anyways). The class is a blueprint that describes the type of data and behavior an instance (or object) of the class would have. Here is an example of what that might look like in Java:

public class Greeter {
  private String greeting;

  Greeter(String aGreeting) {
    this.greeting = aGreeting;
  }

  public void greet() {
    System.out.println(greeting);
  }

}

When you run your program, you instantiate (or create) an object by providing the class that you want to create an instance of. You can then assign it to a variable and call methods (or functions) on it. In Java, it looks like this:

Greeter myGreeter = new Greeter("Hello, World!");
myGreeter.greet();

If you just want to understand the basics of Object Orientation, I would highly recommend a book called The Object-Oriented Thought Process by Matt Weisfeld.

Javid Jamae
A: 

An object is something you (or routine you call) need to do new to create.

Thorbjørn Ravn Andersen
Huh?? In what language is that true?
Potatoswatter
Java. "new Something()" is needed to create a new Something object.
Thorbjørn Ravn Andersen