Question

In: Computer Science

Classes and Objects are the central of Object Oriented Programming (O.O.P.) This is a style of...

Classes and Objects are the central of Object Oriented Programming (O.O.P.) This is a style of programming that focuses on using objects to design and build many great applications.

  1. What is the difference between a class an an instance of the class?
  2. Explain what is constructor? What do you call a constructor that accepts no arguments?
  3. Explain the "has-a" relationship can exist between classes.
  4. Explain what is the "this" keyword?
  5. Do the following:

  6. Answer the 4 points with only one paragraph each. Please note, this assignment needs to be spell and grammar checked prior to posting. (80% of Grade)
  7. Respond to at least two of your classmates findings in the Discussion. (20% of Grade)

Solutions

Expert Solution

Difference between class and instance of a class:

A class is a blueprint which you use to create objects. An object is an instance of a class - it's a concrete 'thing' that you made using a specific class. So, 'object' and 'instance' are the same thing, but the word 'instance' indicates the relationship of an object to its class. For instantiating a class, the 'new' operator instantiates a class by allocating memory for a new object and returning a referebce to that memory. And the new operator also invokes the object constructor. Instantiating a class is nothing but creating an object and when yo create an object , you are actually creating an instance of a class, which is therefore instantiating a class. The name of the constructor provides the name of the class to instantiate.

"has-a" relationship

The has-a relationship is the composition of calsses. When a class is formed as a collection of other classes,it is called aggregation between these classes. It is called as 'has-a' relationship. It simply means that an instance of one class has a reference to an instance of another class or an other instance of the same class =. For example a car has engine and dog barks etc,.

'this' keyword

'this' is a reference variable that refers to the current object. There are 6 usages of this keyword. They are as follows: this can be used to refer current class instance variable, can be used to invoke current class method (implicitly), this() can be used to invoke current class constructor, can be passed as an argument in the method call/ constuctor call, used to return the current class instance from the method. If there is an ambiguity between the instance variables and parameters of a class, this keyword resolves the problem of ambiguity in the program.


Related Solutions

Explain what classes and objects are in object - oriented programming. Give an example of each...
Explain what classes and objects are in object - oriented programming. Give an example of each and explain how they work together in a computer program.
How algorithms address object-oriented classes and objects. What is the File object? How are File objects...
How algorithms address object-oriented classes and objects. What is the File object? How are File objects used in algorithms? 175 words minumum please :)
Java language This is your first homework on objects and classes, and the basics of object-oriented...
Java language This is your first homework on objects and classes, and the basics of object-oriented programming. For each exercise, your task is to first write the class that defines the given object. Compile it and check it for syntax errors. Then write the “demo class” with the main program that creates and uses the object. a)You are planning to purchase a new motor boat for cool cruises on Porter’s Lake this summer, but you want to simulate it before...
Why is it more feasible to use Objects and object oriented programming as compared to using...
Why is it more feasible to use Objects and object oriented programming as compared to using method based programs? What are the disadvantages of using only methods in your programs.
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
C++In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must...
C++In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must quickly...
In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This...
This is Python programming Focus 1. Classes and Objects 2. Creating objects 3. Manipulating objects This lab maps to learning the following objectives: Write a working program that creates a Class, Instances of Objects from that Class, and Functions that use Objects as parameters. For this portion of the lab, you will create a new program for your Professor. Create a class named Student that holds the following data about a student: 1. Name 2. Student ID number 3. GPA...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT