I need defined answers with least 4 sentences to following questions 1) OOP has
ID: 3662015 • Letter: I
Question
I need defined answers with least 4 sentences to following questions
1) OOP has organization..
Why organize?
What did programmers do before OOP?
2) An object is a THING.
The functions are the actions of the 'THING' performs.
The variables store the values that represent the current state of the thing.
Like a MARKER.
The marker can write.. so you need a write function.
The marker has ink, so you need a variable storing the amout of ink still in the marker.
The marker has a cap, so you need a variable storing the value of cap on or cap off.
Before you can use the write funciton, you have to check if the cap is on or off...
Etc...
A object describes a THING... Thing/Object oriented programming...
All the variables and functions are placed TOGETHER in the class definition.....
Makes is easier to understand, debug, change... save time and money...
Makes programming easier, once you learn how to do OOP...
Does this make sense to you ?
3) A static variable is a variable the EXISTS only once,
regardless of how many times a class is declared/instantiated.
It is a way to share data between instances of a class.
Can you Find a video that explains it... ?
4)
A constructor is a function that you can write and put in a class.
A constructor function has the same name as the class.
A constructor function has NO return type.
A constructor function gets AUTOMATICALLY called when you declare/instantiate a class.
Example:
Can you find a video explaining the constructor function .. post it here with a summary..
5) Watch this video about C++ and Classes: http://www.youtube.com/watch?
What did you learn ?
Can you find a good video ?
6) 'What come first, the chicken or the egg'....
.... is asking what comes first, the 'class' or the 'object' ?
So, what does come first?
A constructor is a function that you can write and put in a class.
A constructor function has the same name as the class.
A constructor function has NO return type.
A constructor function gets AUTOMATICALLY called when you declare/instantiate a class.
Example:
Can you find a video explaining the constructor function .. post it here with a summary..
Explanation / Answer
(1) Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.
The programming challenge was seen as how to write the logic, not how to define the data. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them.
The first step in OOP is to identify all the objects the programmer wants to manipulate and how they relate to each other, an exercise often known as data modeling. Once an object has been identified, it is generalized as a class of objects which defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects communicate with well-defined interfaces called messages.
The concepts and rules used in object-oriented programming provide these important benefits:
(2). Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A distinguishing feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of "this" or "self").
Objects sometimes correspond to things found in the real world. For example, a graphics program may have objects such as "circle", "square", "menu". An online shopping system might have objects such as "shopping cart", "customer", and "product".Sometimes objects represent more abstract entities, like an object that represents an open file, or an object which provides the service of translating measurements from U.S. customary to metric.
Each object is said to be an instance of a particular class (for example, an object with its name field set to "Mary" might be an instance of class Employee). Procedures in object-oriented programming are known as methods; variables are also known as fields, members, attributes, or properties. This leads to the following terms:
Object Oriented Programming has great advantages over other programming styles:
(3).
static variable
-It is a variable which belongs to the class and not to object(instance).
-Static variables are initialized only once , at the start of the execution . These variables will be initialized first, before the initialization of any instance variables
-A single copy to be shared by all instances of the class
-A static variable can be accessed directly by the class name and doesn’t need any object
Syntax : class-name.variable-name
static method
It is a method which belongs to the class and not to the object(instance)
A static method can access only static data. It can not access non-static data (instance variables)
A static method can call only other static methods and can not call a non-static method from it.
A static method can be accessed directly by the class name and doesn’t need any object
Syntax : class-name.method-name
A static method cannot refer to “this” or “super” keywords in anyway
video- https://www.youtube.com/watch?v=gTk_F61_-9k
(4). Constructor:-
Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.
video:- https://www.youtube.com/watch?v=7X5hL8pzo_s
(5). C++ and Classes:-
A class in C++ is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private). A class (declared with keyword class) in C++ differs from a structure (declared with keyword struct) as by default, members are private in a class while they are public in a structure. The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class. Instances of these data types are known as objects and can contain member variables, constants, member functions, and overloaded operators defined by the programmer.
In C++, a structure is a class defined with the struct keyword.Its members and base classes are public by default. A class defined with the class keyword has private members and base classes by default. This is the only difference between structs and classes in C++.
video:-https://www.youtube.com/watch?v=O2VlTRZY3yc
(6).
This is the most difficult question in this world ever asked. But i can give you a logical answer for this,so that you can prove your point anywhere.
Let the example of Object oriented programming. According to OOPs concepts:-
Class is a blueprint or template from which objects are created.
and Object is an instance of a class.
From above definitions you can say that..Class comes first
But before saying that consider this:-
"The Object class, in the java.lang package, sits at the top of the class hierarchy tree. Every class is a descendant, direct or indirect, of the Object class. Every class you use or write inherits the instance methods of Object. "
So what comes first , the chicken or the egg.. obviously Egg
then Object comes first.
Hope it will help you to understand the concept behind class and object.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.