Click here to Skip to main content
15,891,253 members
Everything / OOP

OOP

OOP

Great Reads

by Afzaal Ahmad Zeeshan
This post attempts to describe the general difference between overloading and overriding in Object-oriented programming languages.
by Giovanni Scerra
Patterns to prevent null reference exceptions
by Giovanni Scerra
An introduction to transparency in software design, with particular focus on OO languages
by Mahmoud Samir Fayed
Defining Natural Languages in the Ring programming language based on Object-Oriented Programming

Latest Articles

by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
by Alex Rakov, Alexandre Bencz
ELENA is a general-purpose, object-oriented, polymorphic language with late binding
by Bohdan Stupak
A look at what dynamic polymorphism is and how it is crucial to mastering OOP
by Bohdan Stupak
"Method can be static" Microsoft Code Analysis warning may hide a violation of object-oriented design

All Articles

Sort by Updated

OOP 

27 Mar 2024 by Yochai Timmer
A way to avoid JNI's reflection oriented programming. Wrapping Java with C++
20 Feb 2024 by Alex Rakov, Alexandre Bencz
ELENA is a general-purpose, object-oriented, polymorphic language with late binding
12 Dec 2023 by M Imran Ansari
Instance variables are declared/defined in a class but outside the constructor (s), method(s) and block(s). For memory management, when memory is allocated for an object in a heap, a slot for each of the instance variables is created. Further,...
11 Dec 2023 by CPallini
See, for instance: Difference between Instance Variable and Class Variable - GeeksforGeeks[^].
11 Dec 2023 by Member 16128751
Attributes or Properties: Instance variables represent the attributes or properties of an object. For example, if you have a class representing a "Car," instance variables might include attributes like "color," "model," or "year." Scope: The...
11 Dec 2023 by Member 16161055
Memory Overhead : Each instance of a class with its set of instance variables consumes memory. If there are many instances with large sets of variables, it can lead to increased memory usage What I have tried: An instance variable is a variable...
16 Nov 2023 by Dave Kreskowiak
You don't. The site does not allow uploading projects. That would take a lot of disk space and can easily be abused by those who are not trusted. You have to paste the code snippets relevant to the problem, not the entire file(s).
16 Nov 2023 by Krish The Great
Being a beginner,I am having a lot of problems(errors and exceptions) in my java project. How do I share the project here(the files)? What I have tried: I am a beginner is Java oops programming and not able to figure out few problems in my...
9 Nov 2023 by M Imran Ansari
We are here more than happy to help you, but you should try yourself to work on this assignment. Try yourself and come with the issue if you face any. Here is the link to understand the basic concepts of OOP with guide. Introduction to Object...
9 Nov 2023 by Richard MacCutchan
You need to show the code you have written, and explain exactly what help you need. But if you are expecting someone here to write the complete assignment for you, I am afraid you will be disappointed. This site is here to provide help, not to do...
9 Nov 2023 by User204
Write a class Commodity that contains the following attributes and methods: -A public data member Name of type string that represents the Commodity name. -A private data member Quantity that represents the quantity of the Commodity. -A public...
18 Jul 2023 by Shazma Batool
I am learning JavaScript. And this is an object that has two properties; 'color' & 'machine' and one method named 'particulars' Car = { color: 'Red', machine: 12, particulars: function() { return console.log(this.color); return ...
18 Jul 2023 by Member 10601191
try the following. Car = { color: 'Red', machine: 12, particulars: function() { return console.log(this.color, this.machine); } } Car.particulars();
13 Jul 2023 by Samriddha Chowdhury
class Rectangle:Shape { double height; double width; public Rectangle(double height,double width) { this.height=height; this.width=width; } } class Rectangle:Shape { double rec_Height; double...
13 Jul 2023 by Graeme_Grant
Here is the link to the official documentation for the above usage: this keyword - C# Reference | Microsoft Learn[^] Quote: The this keyword refers to the current instance of the class.
13 Jul 2023 by FreedMalloc
The keyword 'this' tells the compiler that you are dealing with a class attribute and not some other variable of the same name. It also tells someone else reading your code that a variable being used is a class attribute and not some other...
27 Jun 2023 by Bohdan Stupak
A look at what dynamic polymorphism is and how it is crucial to mastering OOP
30 May 2023 by Muhammad ali Mansoor
Kv : value_input:value_input TextInput: id: value_input pos: 100, 100 : Button: on_press: root.clear() on_release: root.fill() MainWidget: : ...
29 May 2023 by Daniel Lidén
A simplified version of my problem is: : TextInput: id: value_input on_text_validate: root.value_input(value_input.text) : Button: ...
3 Nov 2022 by shady morsi
Im making an update page. To me it looks strange, because the query function in php is in-built and in my case it should work properly. But it doesn't. My code class update { function GetQuestion($question) { // Question ...
3 Nov 2022 by Richard MacCutchan
Look at your code. You are using the variable $question in three different places for three different purposes ... $sql12query =$question->query("SELECT DISTINCT question FROM questions WHERE uniq_name='" . $question . "'"); ...
23 Oct 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
5 Sep 2022 by #ODSDOMS
The class has the following methods: - A constructor with one tuple argument called coefficients to define and initialize two instant variables, a and b, with default values of 0. - getCoff method that returns a tuple of...
5 Sep 2022 by Richard MacCutchan
Quote: I don't know object-oriented programming Well you will not complete this assignment without some learning materials. Try The Python Tutorial — Python 3.10.6 documentation[^].
16 Aug 2022 by Bohdan Stupak
"Method can be static" Microsoft Code Analysis warning may hide a violation of object-oriented design
28 Jul 2022 by Thandeka Zulu
Compulsory Task 1 In this task, we’re going to be simulating an email message. Some of the logic has been filled out for you in the email.py file. ● Open the file called email.py. ● Create a class definition for an Email which has four variables:...
28 Jul 2022 by OriginalGriff
To add to what Richard has - rightly - said: You should expect to get syntax errors every day, probably many times a day while you are coding - we all do regardless of how much experience we have! Sometimes, we misspell a variable, or a keyword;...
27 Jul 2022 by Richard MacCutchan
You have the following errors, all of which Python tells you: At line 43: userChoice = "" But all the following lines spell it user_choice. At line 47: print(int(input("Enter index of email you want to read: ")) I think you...
14 Jul 2022 by Jaume González
Solution using reflection to dynamically load and execute C# code in a workflow context
31 May 2022 by salam_verdim_alana_panyatkasi_olana
Hi guys, I want to understand what class and object really are. Please don't come to me with simple examples. For example, car class. What I want to understand is how they work. As we really know, everything is made up of classes and objects, but...
31 May 2022 by Richard MacCutchan
See Java Tutorials Learning Paths[^] where it is all clearly explained.
24 May 2022 by Will Sewell
I have two boxes that look like the link below: dateEdit_NightShiftEndDate and timeEdit_NightShiftEndTime[^] I populate these boxes with a variable called NightShiftEndDateTime. I'd like to edit this variable to the value set in the boxes when...
24 May 2022 by OriginalGriff
Convert one to a Timespan, and then add it on to the original DateTime: DateTime start = DateTime.Now.Date; DateTime end = new DateTime (1970, 1, 1, 8, 30, 0); // Midnight is a good starter. // 8 hours, thirty minutes ...
22 May 2022 by Phoenix Liveon
�����Is there a way to have this initialization block similar to Java that we could implement and run properly in C++. There were two types of init-block in Java: 1. init-block/raw-init-block, this will invoke at every new instance created. 2....
13 May 2022 by Member 15635292
hello am making project to calculate the students grade i need to transfer the data from form 1 to form 2 and when i came back to form 1 and entered form 2 again the data can shown how can i do that using class?! What I have tried: ...
13 May 2022 by OriginalGriff
Exactly how depends on the "relationship" between the two forms. Have a look at these, one of them will fit your circumstances. The form that creates an instance of another: MyForm mf = new MyForm(); mf.Show(); Is the "parent", the other form is...
25 Apr 2022 by Member 13661842
Given an array of integers, find the pair of adjacent elements that has the largest sum and return that sum Input Format: An array of integers containing at least 2 elements Output : An integer The largest sum of adjacent elements. Example For inputArray = [3, 6, -2, -5, 7, 3], the output...
18 Apr 2022 by Bohdan Stupak
A short take on brittle unit-tests and how to avoid them
6 Mar 2022 by Junior Frogie
As I know, there are 8 hidden keywords in Java. It's somehow stay invisible in your source code silently, such as this, extend Object, super, constructor, import system.lang, return. But there are still two left. I wonder what are they. Please leave your comment here.
23 Feb 2022 by Michael Sydney Balloni
Recycle objects that are expensive to create and improve the performance of your application
22 Feb 2022 by 1298201
#include #include // FUNCTIONS void menu(); void account(int option); using namespace std; string AccountType[] = {"", "CHECKINGS", "SAVINGS"}; string response; int AccountDetails[] = { 1234, // pin number 10000, //...
22 Feb 2022 by I_M_R
Hello, As i see by checking whole code: That code declares a class and defines (the body) that class with private and public attributes and methods. That is all. That would be very nice to define classes in a seperate header file or source file....
8 Feb 2022 by Cameron Grant 2021
Just been experimenting with a class in which two dice are thrown and the total values of the numbers shown are calculated. I am using OOP and setting the total to this.dice1 + this.dice2. However, when instantiating a Dice in another class the...
8 Feb 2022 by Richard Deeming
You never call your setSumTotal function except from the constructor with two arguments. Either call that method from your setDice1 and setDice2 methods, or call it from the rollDice method. public void rollDice() { ...
30 Jan 2022 by CPallini
In my personal opinion, it is an unfortunate example of OOP (the AccountSettings class acts on a global variables, like AccountDetails, AccountType).
30 Jan 2022 by OriginalGriff
No, it isn't. Not even close. it looks like C code that has been "converted to C++" by changing printf to cout, and adding an irrelevant "class" is all. Go back to your recent tutorials and read your notes over again: you don't seem to have...
6 Jan 2022 by Bernhard Nebel
Link-time optimization and debugging OO programs do not work very well together, at least on AVR MCUs.
5 Jan 2022 by Stefan_Lang
You seem to try and imprint another languages' properties onto C++, and that is never a good idea! My experience with java is limited, and I'm not sure what you actually have in mind, but the code you posted is clearly not the recommended way of...
5 Jan 2022 by Phoenix Liveon
What I did for now was to call/invoked it inside of the first line of one of any constructor, Note: upon by doing it we need to have a delegated constructor if we do had multiple overloaded constructors, so that we could link it together, then...
3 Jan 2022 by Mustafa Marri
The Australian cricket team is the best team in the world. The Australian Cricket Board that handles the payment related issues of the players has decided to develop software that would automatically Calculates the income of the players based on...
3 Jan 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
31 Dec 2021 by Richard MacCutchan
You could probably simplify that by the use of the singleton pattern - Google Search[^].
27 Dec 2021 by Innam Afridi
#include #include using namespace std; class Employee { string name; double hourwork, wage, netsal; public: void getEmployee(string &Name, double &hourWork, double &Wage) { name = Name; ...
27 Dec 2021 by KarstenK
You didnt read the tutorial I advised you. You need to create an instance of the employee and fill its members. Write a member function of the class and use it. Use the debugger to understand your code.
27 Dec 2021 by OriginalGriff
Quote: First I tried if else but did'nt work and changed the code 6th time still it does not give the result according to the question Making random changes isn't going to get you anywhere: you need to sit down and think before you even start to...
27 Dec 2021 by Richard MacCutchan
You already posted this question at I have a project on OOP C++ to code a program on salary.[^]. Please do not repost. If you have additional information then please use the Improve question link in the original post, and add the details there.
26 Dec 2021 by Innam Afridi
Q.No.1: A company pays its employees on a weekly basis. The employees are of two types: 1. Salaried Employees 2. Hourly Employees Salaried employees are paid with a fixed weekly salary, regardless of the number of hours they worked. Fix week...
26 Dec 2021 by KarstenK
Start with some Learn C++ tutorial to learn the language and think over your task. Best is to make some sketch about all functions and members. You may end up with an Employee class which has a boolean for hourly pay, so you can use an if-else...
26 Dec 2021 by k5054
Innam Afridi wrote: don't know how to code. That's a problem. This site assumes that you know how to code, and have at least attempted to try to solve the problem. If you don't know how to code, then its time for you to drop this course. Its...
21 Dec 2021 by biull smith
If such a request has already been asked, please accept my apologies. I looked for samples, read up on the player and monster classes, and player and monster stats on other sites, and nothing appeared to fit with the game's code without...
21 Dec 2021 by Gerry Schmitz
You need a "standard" / baseline for inflicting damage; then you vary the damage as the strength varies. e.g. One company (64 men), lying down, open formation, firing, can inflict a loss of 5, in one minute, on the party fired on under similar...
19 Dec 2021 by Zhobk
public classffdgd { public String osdfwnerName = “CzzIUsgdz"; public String szbrand; public int zsuzsrrentSzspeed; pritate vosid sdzgccgzdelezgrate(int speed) { ... } pritate void fsdfecelgdesrate(int speed) { ... } pritate void...
16 Dec 2021 by Richard MacCutchan
See Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)[^].
16 Dec 2021 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
3 Dec 2021 by JacobFish2
I am writing a program similar to peg solitaire. I can not get it to work properly and I have attached all the code that I have so far. Any help/advice is appreciated. The outline of the game is to have the player pick the amount of columns and...
3 Dec 2021 by OriginalGriff
Start by thinking about how you would do in manually: how do you decide if a move will be allowed when you play the game in the real world? Simple: you look beside teh peg you want to move, and check there is a peg there, and that where the peg...
15 Nov 2021 by Member 14430889
Example : Input Two Any Value With Int Type, Call Them 'A', 'B'. User Can Input A Positive Value For How Many Times The System Creates A Random Number 'M' , A
15 Nov 2021 by Member 14430889
Before Fix (Horrible) : using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using...
7 Nov 2021 by BillWoodruff
In addition to Richard MacCutchan's and OriginalGriff's excellent advice: Break the problem into small steps: 1) create three controls on the Form for text/number entry 1a) verify that you can get valid integer values from those controls: use...
6 Nov 2021 by OriginalGriff
Quote: I Can Not Totally UnderStand How To Use 'Key' And 'Value' Of List And Dictionary. Lists don't have "Key" or "Value" - dictionaries do because they store two bits of information: a Key which must be unique and a Value which is associated...
31 Oct 2021 by kawaii simp
Questionnaire Type Program in C++ with 3 items of questions. When the user finish answering the 3 items of questions, the program will compute the total number of correct and wrong answer(s). Then, the program will ask if the user want to take...
23 Oct 2021 by merano99
There's no question, but I'll give you an assumed answer. With cin the variable "answer" is read in, but then "x" is evaluated. The for loop doesn't seem to make any sense. I would put questions and possible answers that the program generates in...
23 Oct 2021 by Greg Utas
For one thing, studentInfo never assigns a value to age, so it will probably be a random value when displayAnswerQuestionInfo displays it.
9 Oct 2021 by Nirosh
This article helps to understand OOP concepts, focusing on .NET/ C#. This is written in the form of asking questions and writing answers to them, making it easy to understand.
13 Sep 2021 by walied sharkawy
if I have a copy constructor in which the class is being passed by reference for example Move::Move(const Move& source) { data = new int; *data = *source.data; } where is the class of data attribute that I'm copying source.data within...
13 Sep 2021 by Richard Deeming
Not like that! Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can...
13 Sep 2021 by Member 14961132
private void btnConfirm_Click(object sender, EventArgs e) { string product_id = txtProductID.Text; string product_name = txtProductName.Text; string product_price = txtPrice.Text; string...
12 Sep 2021 by walied sharkawy
I've written a code in which I'm passing class as a parameter in fucntion the copy constructor for the class is written too in the body of the code #include #include using namespace std; class Move { private: int* age;...
12 Sep 2021 by CPallini
Quote: I'm wondering where is the object of the (*age) member in the copy constructor body? Quote: I've tried to debug and see locals to see what's going behind I see a pointer variable called this is being created when the constructor is called...
12 Sep 2021 by BernardIE5317
Your ultimate intention is not clear Do you merely want working code or are you investigating memory structures created by the compiler As to your example you will have to delete the destination pointer before assigning it a new value else you...
12 Sep 2021 by BernardIE5317
It seems to me there is no need to utilize a pointer to store age as shown below If you wish to utilize a pointer you should delete it before copying to it in the copy constructor else you will have memory leakage As to your question if I...
12 Sep 2021 by Rick York
I am not sure I fully understand your question but for that code to work there has to be a declaration like this somewhere : class Move { public: Move(const Move& source); int * data; };
10 Sep 2021 by Priyanka Somani
Given as input a list of integers nums and an integer k, return the maximum value of each sub-list of length k Example: nums = [4, 8, 2, 4, 10, 12] k = 2 Output = [8, 8, 4, 10, 12] Your task is to create a class named SlidingWindow and implement...
23 Aug 2021 by Joi Master
Define a class Counter having the attribute count (type int). For the class Counter, implement the following functionalities: (Q8-Q11) Q8. Constructors which allow statements like: Counter c1;//count should be 0 for c1, Counter c2(12);// count...
23 Aug 2021 by KarstenK
You need to improve your coding skills with some Learn C++ tutorial and write some C++ code with classes. If you use Microsoft Visual Studio you get an assistent which does half of the work for free.
22 Aug 2021 by Richard MacCutchan
Q8. Create two constructors, one which does not accept any parameters, and a second one which requires an integer value. Q9. Provide the code for an overload of the += operator. Q10. Provide an overload for the two decrement operators. Q11....
22 Aug 2021 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
19 Jul 2021 by Richard MacCutchan
Java Tutorials Learning Paths[^]
19 Jul 2021 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
17 Jul 2021 by Hemil Shah 2021
I am actually getting " expected " error for parameters passed in methods. What I have tried: import java.util.Scanner; import java.lang.Math; class Quad { int a,b,c; float d,x1,x2; void discriminant( a, b,...
17 Jul 2021 by Richard MacCutchan
You need to declare the parameter types in your function definitions: void discriminant( a, b, c) // the compiler cannot guess the types of a, b and c // correct way void discriminant(int a, int b, int c) // tell the compiler the types of the...
23 Jun 2021 by Shivprasad koirala
In this article we will try to understand 3 important concepts association, aggregation and composition.
14 Jun 2021 by Zeeshan Mehmood Jun2021
We want to store the information of different vehicles. Create a class named Vehicle with two data member named mileage and price. Create its two subclasses *Car with data members to store ownership cost, warranty (by years), seating capacity...
14 Jun 2021 by Richard MacCutchan
class Vehicle { int mileage; int price; };
14 Jun 2021 by KarstenK
You need to visit some Learn C++ tutorial and learn basic programming. tip 1: use the std:string class tip 2: write functions for every task tip 3: write tests for all functions and check for correct results
11 Jun 2021 by Alvin Smith
Hello! I'm new to Java programming and Object-oriented programming. Please help me. I have 6 classes here: Bank, Customer, Account, CheckingAccount, SavingsAccount, and TestBanking. A Bank can have multiple customers(but i initialize the num of...