1 Introduction

Object-oriented programming (OOP) is widely taught in high schools and at institutions of higher learning. Difficulties, conceptions, and misconceptions in understanding core OOP concepts are extensively discussed in research on computer science (CS) education (e.g., Fleury 2000; Holland et al. 1997; Kaczmarczyk et al. 2010; Kanaki and Kalogiannakis 2018; Qian and Lehman 2017; Shmallo et al. 2012; Sorva 2007, 2008; Xinogalos 2016). Students face obstacles related to even basic concepts, such as “object” and “class” (Holland et al. 1997; Sanders et al. 2008). The misunderstanding of the “current object” and its notation in programming—the this reference—appears in the context of understanding OOP concepts, but it has not been directly addressed in previous research (Chen et al. 2012; Ragonis and Ben-Ari 2005).

Understanding the this reference involves abstraction, aspects of memory management, and aspects of program execution. This complexity requires careful development of students’ conceptual knowledge so they can build proper mental models (Byrnes and Wasik 1991; Qian and Lehman 2017). CS teachers have to become familiar with students’ common misconceptions to be able to identify them, especially the latent ones (Hazzan et al. 2020; Qian et al. 2019).

We conducted the present study to expose students’ difficulties, misconceptions, and perceptions in relation to the this reference, and to this end we posed five research questions. To carry this out, we developed a diagnostic tool (see Appendix 1). The tool is presented in Java and can be translated to any other OOP language. The interpretation that led the development of the diagnostic tool is comprehensively described in Ragonis and Shmallo (2018). The tool was used with 86 high school (HS) students and 77 college engineering (CE) students. Partial results obtained from analyzing the HS students’ answers to two of the five questions (2 and 5) were presented in Ragonis and Shmallo (2017); that study included insights from the HS teachers. The current paper presents the analysis of students’ answers to the questions for both groups of participants, HS and CE, and based on that it offers answers to the research questions.

2 Background

The reserved word this is used in OO programming languages, such as Java and C#. In Oracle Java documentation, “this is a reference to the current object—the object whose method or constructor is being called upon” (Oracle n.d.). This is similar to the definition of this in textbooks (e.g., Lewis and Loftus 2009, p. 321; Roberts 2007, p. 200).

The common usages of this are as follows (JavaTpoint n.d.):

  1. 1.

    To refer to a current class instance variable—e.g., this.attribute_name;

  2. 2.

    To invoke a current class method—e.g., this.instance_method_name(…);

  3. 3.

    To invoke a current class overloaded constructor—e.g., this();

  4. 4.

    To determine an actual parameter in a method call—e.g., instance_method_name(this).

Specifying this is mandatory to distinguish between parameters and their corresponding instance variables when both share the same names. Programmers commonly use this to point out the connection between the current object and its own attributes and methods, even when doing so is not mandatory. This is mainly manifested in the constructors and setters methods. In static methods, this cannot be used, since no current object exists.

2.1 Object conceptualization

Proper conceptualization of this indicates understanding of the fundamental OOP concept “object”. Many studies have investigated how students cope with the core concepts of OOP: class, object, constructor, encapsulation, attributes, methods, and object state (e.g., Holland et al. 1997; Sanders et al. 2008; Shmallo et al. 2012; Sorva 2007; Xinogalos 2015). In particular, several misconceptions regarding the “object” concept were identified: objects were considered “regular” variables (Fleury 2000); an object and its attributes were confused (e.g., Sorva 2008); object and class were mixed up (e.g., Holland et al. 1997; Sanders et al. 2008); the object instance and the identifier variable referencing it were not distinguished (Holland et al. 1997; Sorva 2008); and the relationship between objects and methods was misunderstood (Sajaniemi et al. 2008).

2.2 Object abstraction

Abstraction, which is known to be difficult for novices (Haberman and Muller 2008), is central to OOP and is articulated in the design, representation, and execution of a project. The understanding of the this reference involves abstraction processes that are strictly enforced by the basic aspects of an object—a capsule with hidden structure and hidden content. The attributes of an object are private, accessible only via getters and setters methods that enable access to the information while hiding the details of its internal structure (Goldberg and Robson 1983). Furthermore, the object’s abstract interface is the sole means of evoking the behavior of an object (Rosson and Alpert 1990). Using the this annotation adds another aspect of abstraction, since the object identifier is not used. Some previous studies presented students’ difficulties regarding “object” and “the current object” that expressed a lack of abstraction. For example, novices could not understand how this can refer to something different each time (Ragonis and Ben-Ari 2005), and students confused the use of formal parameters with actual parameters when this was used to define a new constructor for calling another constructor in the same class (Chen et al. 2012).

2.3 Objects in relation to memory management and program execution

Understanding what the this reference means and using it correctly also involve aspects of memory management and program execution. The ubiquitous issue of hidden internal changes of the machine state is not externally signaled in a clear way; for novices this causes problems, which are expressed as an inaccurate mental model (Du Boulay 1986). The this notation can be seen as a pointer, which is recognized as being among the most difficult concepts that have to do with the execution-time use of memory (Milne and Rowe 2002). Research on student errors with Python has pointed out that reference errors were more common than other types of error (Miller and Settle 2016). In that study, most students had difficulty with the instance (self) object and omitted the parameter in the method definition or failed to use the instance object when referencing attributes of the object.

In the framework of OOP, some students have misconceptions about memory models:

  • Students wrongly interpret how the computer keeps track of object data (Sorva 2007);

  • Students think that no memory is allocated for an instantiated object and that all objects are allocated the same amount of memory regardless of definition or instantiation (Kaczmarczyk et al. 2010); and

  • Students rely on aspects of hidden processes within the execution time of the notional machine, such as references and objects, which creates difficulties for novice programmers (Sorva 2013).

A review of the studies revealed that students learning OOP face various obstacles in relation to the this reference, which is reflected in programming tasks. Hence, we wished to systematically uncover students’ conceptions, perceptions, and misconceptions in relation to this.

3 Research description

The research section includes the research questions, a description of the research participants, the structure of the tool, and the methods used to analyze the data.

3.1 Questions

The following research questions were posed:

  1. 1.

    Do students recognize where this must or must not be used in a given code? And which justifications do they provide?

  2. 2.

    What are students’ personal preferences regarding using this, and what reasons do they provide?

  3. 3.

    How do students understand the execution of program statements when using this in different contexts (e.g., simple class, composed class, inheritance, as a parameter, or as method call to constructors)?

  4. 4.

    How do students conceptualize their understanding of this?

  5. 5.

    What are the differences between high school students’ and college engineering students’ conception of this?

3.2 Participants

The study was conducted among participants from two groups: 86 high school students (HS) who were learning CS; and 77 college engineering students (CE) in the Information Systems program.

The HS students were from seven high schools and in grades 10–12. Among the schools, four used Java and three used C#. The students were completing their OOP studies (45-min classes, for a total of 270 lessons) and were about to take the national matriculation exam.

The CE students were in their third of 4 years of study and used C#. The students were completing their OOP studies (50-min classes, for a total of 180 lessons) and were about to take the final exam. Most of the third-year CE students (97%) had no previous knowledge from high school about programming in general or OOP in particular.

Students in both groups of participants gained similar knowledge and followed similar practices; the common use of this in teaching was in relation to constructors and setters methods. Students’ familiarity with OOP in general, and with the this reference in particular, should have enabled them to deal successfully with all parts of the questionnaire. The exception was in relation to the use of this as a parameter: neither the class materials, nor the exercises, nor the exams included that use of this. But it was reasonable to expect students to implement what they had already grasped in a new context. There was nothing more to teach for a student to be able to cope with that use. We wanted to see whether any differences would be found between the groups of participants, perhaps attributable to different teaching approaches or to age (HS: 17–18 years old; CE: 24 years old and up). Differences related to the age aspect can be expressed in students’ commitment and learning orientation. Using either Java or C# language was not a confounding factor, since the languages are similar in their use of this.

3.3 Tool

The research tool consisted of five questions, each focused on different aspects of understanding and using the this notation:

  • Question 1: Where is the use of this needed?

  • Question 2: Personal preferences in using this.

  • Question 3: Use of this as a parameter.

  • Question 4: Use of this to invoke a current class overloaded constructor.

  • Question 5: Open comprehension question.

Each of the questions contained several clauses and combined a variety of interpretations. The first four questions were based on a given project, so the questions were grounded in a relevant context. The last question was an open question, which can be seen as a summary of students’ conceptions. The type of answer required was varied: for example, determining the correctness of a given code and explaining their answer; ranking their preferred code versions and justifying the ranking; and following a program execution. Three of the four common usages of this mentioned in the Background section were directly addressed in the questionnaire: usage No. 1 in questions 1 and 2; usage No. 3 in question 4; and usage No. 4 in question 3. Usage No. 2 (invoking a method) was not tested, since it is not mandatory and is a matter of personal preference, which is similar to reference to attributes (usage No. 1). The questionnaire is presented in Appendix 1.

The questionnaire was completed by students as a class exercise; a Google Docs form was used to collect their answers. Each class was presented with the questionnaire in the programming language used in the class.

3.4 Methods

The study applied a mixed methods approach, combining qualitative and quantitative methods (Creswell and Creswell 2018). When analyzing the answers, we gave importance to the explanations and reasons the students gave, not just to the correctness of the answers, since students’ justifications revealed their perceptions. For each question we applied the content analysis method to the students’ open answers—explanations and justifications. First, we sorted the answers into two main categories: explanations that “expressed understanding” and explanations that “expressed misunderstanding.” Second, for the answers that expressed misunderstanding, we identified some subcategories according to the source of the wrong or inaccurate answer. After identifying the subcategories with respect to each question, we analyzed all the answers accordingly. Following the qualitative analysis, we performed frequency analysis for the answers’ correctness and for the explanations’ categories.

4 Research findings

Our research findings are presented in the order of the questionnaire questions. For each question we present a description of the question; quantitative analysis and answers distribution, separating the two groups of participants; and, when relevant, inferential tests for differences between the groups; and qualitative analysis of students’ open answers.

The code presented here is partial; the full text of the questionnaire appears in Appendix 1.

4.1 Question 1: Where is the use of This needed?

Question 1 presented a project that contained a simple class, a composed class, and a main class. The purpose was to examine whether students could identify where this must be used when parameters and attributes have the same identifier names.

4.1.1 Question 1, clause (a)

Students were asked to mark where this was required and where it was superfluous and to explain their determination. The codes were related to (1) a parameter constructor that used parameters with the same identifier names as the attributes; (2) a copy constructor; (3) the toString() method; and (4) the equals(…) method. Table 1 presents the analysis of students’ answers for each group (HS, CE). For each code version, the first row indicates the percentage of students that gave the correct answer, and below that is a categorization of students’ explanations to support their answers. It should be noted that even students who presented correct answers gave wrong explanations. For example, for code No. 1, 86% of the HS students gave correct answers, but only 43% of them expressed an understanding in their explanation, while 50% of them expressed a misunderstanding, and 7% did not give an explanation. To test the correlation between the two groups of participants we used Pearson’s (1) test of difference between two proportions for all exhibited proportions; and (2) chi-square test for frequency comparisons of types of correct answers.

Table 1 Percentage of Students’ Answers for Question 1a: “Where Must this Be Used?”

Quantitative analysis

The two groups (HS, CE) expressed similar knowledge regarding the most usual use of this, as a parameter constructor. However, there were differences in knowledge about the other three codes: the CE students were more successful. Setting the p value cutoff below .05, we argue that the proportion of correct answers was significantly greater for the CE students than for the HS students in clauses (a) 2, 3, and 4. Although the CE students did better in determining whether this must be used in all code contexts, the students in both groups expressed a similar understanding in the arguments they used to support their answers. This further analysis is supported by Pearson’s chi-square test: that is, we tested whether the distribution of the correct answers was similar across the two groups. The results, provided at the bottom of the table, show that this distribution was similar in clauses (a) 2, 3, and 4, but not in clause 1. For example, regarding the copy constructor, while only 57% of the HS students gave a correct answer, 82% of the CE students answered correctly. But the number of students that presented a correct argument is similar: 47% of the HS students and 52% of the CE students.

Qualitative analysis

Students’ explanations that expressed a misunderstanding can be divided into four categories: (a) misunderstanding of the compiler—this is required, since “otherwise the computer will be confused” / “the computer will not know to which variable to relate”; (b) lack of programming knowledge—“It is not possible to access attributes without using this” / “Without using this it will not work”; (c) conventions or mantras—“It is easier to use this” / “We did not learn otherwise”; (d) personalization of the computer—this is not required, since “the computer knows that in the right side are the parameters and in the left the attributes.”

4.1.2 Question 1, clause (b)

Students were asked to determine what the this appearing in the equals method refers to. Students were expected to relate to the particular object flight001. Yet some students generalized their answer and related to the “object” in general, or they failed in their explanations. Table 2 presents the percentage of students in each group of participants according to three categories expressed in their answers.

Table 2 Percentage of Students’ Answers for Question 1b: “To What Does this Refer?”

Quantitative analysis

Neither of the student groups showed an understanding to the expected extent. However, the CE students provided a higher rate of correct answers (p < .001). Altogether, the distribution of answers for the two groups varied as shown in the chi-square test results. The HS students applied generalization more than the CE students did (p < .001). We consider the generalized answer correct, since those students presented a correct conception, even though they were asked to relate to a particular code.

Qualitative analysis

Students that expressed a misunderstanding noted that this refers to attributes or attributes’ values or class variables, instead of relating to the entire object. For example, “this refers to the flight date attribute” / “this refers to the object attributes” / “to the given variable”. Some students gave an explanation that related to the purpose of any equals method, which is a comparison of two objects — “the equals method compares between two objects”, or to the purpose of the particular equals method presented in the code that compares two dates — “the equals method compares between two Flights”.

4.1.3 Question 1, clause (c)

Students were asked to develop an external static method replacing the instance method equals in the class Date. Success in this clause involves some significant OOP principles besides omitting the reference to this. In general, students face obstacles in relation to static context. In this question, they needed to confront the meanings of internal versus external methods, which have the same aim. Moreover, the solution involves the current object, which is a hidden parameter in the internal method but should be a formal parameter in the external method.

The changing of method context from internal to external static must be expressed in four components: (1) the reserved word static should be included in the method signature; (2) two parameters for the two compared objects should appear; (3) the this reserved word should be omitted from the method body; and (4) the comparison between the values of the objects’ attributes should use the getters method. Rows 1–4 in Table 3 present the percentage of students in each of the two groups, categorized according to the four needed changes. Line 5 presents the percentage of students that made all four needed changes, and line 6 presents the percentage of students that made three changes without using the getters method.

Table 3 Percentage of Students’ Answers for Question 1c: Formulating Internal Method as an External Static Method

Quantitative analysis

For the first three of the needed changes (rows 1–3), we can see that most students correctly omitted the this notation, fewer students added static, and only about half the students used two parameters instead of one. The most significant lack of knowledge was in relation to the concept of data hiding. The getters method should be used, since the new method is external and cannot access private attributes. Most students failed to include the getters method (row 4) to access the attribute’s values, meaning they did not include all four needed changes. When students were relating to changes 1–3 without adding getters, the percentage increased. Across changes 1–3 (point 6 in Table 3), the HS group expressed greater understanding than the CE group, but the difference was not significant.

Qualitative analysis

No reference is given, since students did not need to give an explanation in this clause.

4.1.4 Question 1, clause (d)

Students were asked to generalize their conceptions and to answer the question “Can this be used in the code of the main method?”

Quantitative analysis

Most of the students answered correctly (HS, 86%; CE, 87%; no difference, p = .991), but 12% of the HS students and 28% of the CE students supported their answers incorrectly.

Qualitative analysis

Some students related to the role of this to distinguish between parameters and object attributes, and some believed that it could only be used in constructors: “It is not needed, since the main method does not define attributes” and “this serves to collaborate between constructors, and in the main method there are no constructors.” Students who gave the wrong answer claimed that this can be used in the main method: “this is not restricted only to objects; it can appear everywhere” and “If in the main method we use variables with the same names as attributes, we should use this.”

4.2 Question 2: Personal preferences in using this

Question 2 related to the class Point. The question included four clauses, each displaying two or three different codes that execute the same task. The students were required to rank the versions in each clause according to their personal preference and to specify their criteria for making this choice. The questionnaire clearly stated that all versions were syntactically correct. In what follows, we present the analysis of clauses (a) and (b), omitting clauses (c) and (d), which are less commonly used. Tables 4 and 5 present the percentages of students who chose each version as their first priority.

Table 4 Percentage of Students’ Preferences for Question 2a
Table 5 Percentage of Students’ Preferences for Question 2b

4.2.1 Question 2(a): Initializing attributes by constant values

The three code versions create objects of the class Point with equal attribute values, x = 0 and y = 0. Table 4 presents the percentage of students’ preferences for question 2a for each group (HS, CE).

Quantitative analysis

The student groups differed in their preferences in regard to the two most common versions (ver. 2, p < .002; ver. 3, p < .001).

Qualitative analysis

The HS students’ first choice was version 2. The common reasons mentioned were correctness (“It is the most correct” / “Acceptable version”); readability (“Easier to understand”); convention (“This is what we learned” / “this must be included”); and programming aspects (“It is easier to make changes to the constructor, since we won’t have to touch the left side”).

The CE students’ first choice was version 3. The most common reasons mentioned were correctness (“It is more accurate to initialize the attributes directly in the constructor”); readability (“The use of this is startling and less intuitive”); convention (“The most standard and non-sophisticated version”); and programming aspects (“The constructor is without parameters; hence the this is not needed”). The students’ explanations do not reflect a misunderstanding, but rather preferences likely influenced by the examples presented during their learning process. The HS students preferred the use of this similar to the use of this in the traditional parameters constructor, while the CE students’ top criterion was whether this was required or not.

4.2.2 Question 2(b): Initializing attributes by parameters

The two code versions initialized the object attributes by parameters. Table 5 presents the percentage of students’ preferences for question 2b for each group (HS, CE).

Quantitative analysis

Both groups of participants preferred version 2; no statistical difference was detected.

Qualitative analysis

The most common reasons mentioned were readability (“The use of this prevents confusion” / “this makes it clearer to me”); convention (“this is the acceptable programming approach”/ “This is what we learned”); correctness (“there must be this, since the parameters have the same name as the attributes”); and programming aspects (“It is better to use fewer variables”).

4.3 Question 3: Use of this as a parameter

Question 3 relates to a project including a simple class Circle and a main class Test. The question focuses on the use of this as a parameter. Students are required to refer to the execution of the instruction circle1.chooseWhatToDraw(‘F’, circle2); in the main method and to answer to what the this appearing in the method chooseWhatToDraw(…) in the instruction drawFlower(this); refers. The method is presented in Table 6. Using this as a parameter is rarely taught in class. It was expected that students who grasped the “object” concept, particularly those who understood the role of the object in instance methods, would be able to apply it in the new context.

Table 6 Percentage of Students’ Answers to Question 3

Quantitative analysis

No statistical difference was detected (except the non-meaningful data about students who did not answer the question).

Qualitative analysis

Students’ correct answers should relate to the particular object circle1, which is involved in the process. Students’ answers were classified into four categories. Around one third of the students in both groups gave the correct answer. Approximately one quarter of the students in both groups generalized the context and gave a general reference to an object, omitting the particular involved object. The other students did not answer at all or gave wrong answers: “It relates to the class Circle” (confusion between object and class); “It relates to the Circle class attributes” (misunderstanding of the object as a capsule); and “It relates to the object circ” (confusion with the formal parameter of the method). One significant mistake was “It relates to circle2.” Those students confused the object on which the method operated (circle1) with the other object that served as an actual parameter (circle2). In our interpretation, those students faced obstacles in moving from the visible object circle1 to the “invisible” object this; then they chose the object circle2 because it was easier for them to associate the actual parameter with the formal parameter.

4.4 Question 4: Use of this to invoke a current class overloaded constructor

Question 4 relates to a project that included classes AA and Program. We wished to examine the use of this to invoke an overloaded constructor. Students were asked to follow the execution of the main method by drawing a trace table and to display the program output, and further to deter00mine what the this refers to in two marked instructions: that, when executing the particular object creation in the main method, AA a = new AA();. The overloaded constructors of class AA are presented in Table 7.

Table 7 Question 4 Code

Quantitative analysis

Most students (82%) did not answer the question, so we are not presenting statistical data.

Qualitative analysis

Of the students that did answer, 83% noted correctly in relation to line #1 that the this calls another constructor of the same class. But in relation to line #2, where the use of this is common (refers to the current object attribute), only 13% answered correctly. Most of the students referred to the attribute x, so they answered to whom the this.x referred and not to what the this itself referred.

4.5 Question 5: Open comprehension question

Question 5 required students to conceptualize their insights in writing and therefore to formalize their understanding. The question was the last in the questionnaire, so students had the opportunity to learn and reflect on the meaning of this and its different usages while answering the previous questions. The question clauses appear in Table 8.

Table 8 Question 5 Clauses

4.5.1 Students’ perspective on clauses (a)–(c)

Only 45% of the HS students and 40% of the CE students correctly indicated when this must be used, and only half of them, from both groups of participants, used precise concepts in their answers. When relating to the question of when this should be used, 29% of the HS students stated that they recommend always using it; only 11% of the CE students stated the same. Students referred to the clarity of the code formulation: 19% of the HS students and 7% of the CE students wrote that it is more ordered / clear / clean / aesthetic or avoids confusion. Finally, 60% of the HS students and 45% of the CE students indicated correctly when this should not be used, 24% of the HS students explicitly mentioned that they did not know the answer, and 45% of the CE students did not write an answer at all.

4.5.2 Students’ perspective on “What Is this?” clause (d)

Students’ answers to the question “What is this?” were categorized according to the leading concept they used in their answers, as presented in Table 9.

Table 9 Percentages of Classifications of Students’ Answers to the Question “What Is this?”

Classification 1: The current object

While the frequent answer was “the current object” (HS, 40%; CE, 38%), this was not a majority, being less than half.

Classifications 2 and 3: Referral to attribute or to method

A significant number of students (in total, 28% in HS, 37% in CE) chose the practical operative approach of this as a pointer, most of them in relation to attributes and fewer in relation to methods.

Classifications 4–8

Those classifications are incorrect and express misconceptions (in total, 13% in HS and 17% in CE).

Classification 9: Do not know

A substantial number of students did not give any relevant answer, stating “Do not know” or gave inaccurate answers, but this rate was higher in the HS group (19%) than in the CE group (8%).

5 Discussion

The diagnostic questionnaire enabled us to uncover a lack of clarity in relation to the this concept and to other OOP concepts as well. The detailed findings show that there were difficulties in perceiving the meaning of this as the current object, the sense of the this notation, and the different usages of this in code. The obstacles were widely expressed in all questions where most students, in both groups of participants, did not show the expected understanding and insights. We will address the findings holistically in relation to the research questions without separating the groups and while combining findings from all five questionnaire questions. We first address the main conceptions students hold in relation to the use of this in different contexts, then we characterize nine misconceptions that students expressed in their answers, after which we answer the research questions. In the summary, we map the findings in relation to the research design—tool questions, research questions, and usages of this.

5.1 Students’ conceptions of “What Is this” in different contexts

It appears that students face and use the this notation mostly in constructors, particularly in the parameter constructor, which has a parameter for each attribute that bears the same identifier. Students presented justifications to support the usages of this that were not related to correctness, such as using this is more ordered / clear / clean / aesthetic or avoids confusion. Those justifications show that students followed the traditions presented in class, rather than expressing understanding. Frequently, students mixed up OOP core concepts and did not clearly distinguish between class, object, attributes, or methods.

Students make generalizations, which could be seen as a positive approach that evidences understanding. But from an inspection of students’ explanations it looks more like they were quoting a mantra than expressing meaningful understanding. For example, some students explained the rule of the equals method instead of explaining a particular needed aspect of a specific equals method; or they gave a general answer that says a method relates to the object on which it is activated, without relating to the particular code that was presented.

It is noticeable that students followed “rules of thumb” and did not express comprehension of the principles that form the basis of those rules. For example, some students claimed that this must be used in any constructor while relating to attributes; and where students needed to convert an internal method to an external method, they included the reserved word static in the signature of the external static method and omitted the use of this in the body of the method, but they failed to add a second parameter for the “current object.”

The questionnaire included two questions where the use of this was in more advanced and complex contexts: when using this as a parameter; and when using this to invoke a current class overloaded constructor. It was a good opportunity to indicate their abilities to implement and transfer knowledge to new frameworks. Most of the students failed in that.

It appears that the students were influenced by the verbal formulation of the concepts in their classes and by the examples they used. Some students used statements like “this must be used” when it was not, and some students explicitly wrote “That is what we learned.” Another observation is in relation to students’ arguments. In their explanations, some students used meaningful characteristics, such as correctness, programming aspects, readability, and convention. But the explanations in many cases were erroneous. For example, a reason to choose the traditional constructor, which relates to programming aspects, was that “It is more efficient”; or, when omitting the use of this in a constructor, they claimed “It will not work”.

5.2 Misconceptions regarding “this”

The findings reveal nine inaccurate perceptions and misconceptions:

  1. 1.

    The this is not an object—Some students did not internalize the principle of encapsulation. Rather, they mainly referred to a collection of attributes, and in addition to a collection of methods. This manifested mainly in the analysis of questions 1b, 3.

  2. 2.

    The this notation is only a reference—Many students related to this only as a reference to an attribute or to a method. This manifested mainly in the analysis of questions 1a, 5d.

  3. 3.

    The this refers to other types of concepts—Students used formulations that were not clear and did not distinguish between different basic OOP concepts. Students mentioned, for example, that this is a class, a method, an attribute, an operator, or a variable. This manifested mainly in the analysis of questions 1b, 3, 4, 5d.

  4. 4.

    The term this is used only in constructors—Many students believed that this is used only in constructors. That restriction makes it evident that students missed the meaning of the current object. This manifested mainly in the analysis of questions 1d, 2a, 2b.

  5. 5.

    The term this is just to distinguish between attributes and parameters—Students reduced the meaning of this from being an object to being just a notation distinguishing between attributes and parameters. This manifested mainly in the analysis of questions 1d, 3.

  6. 6.

    There is a failure to indicate when this must be used—Students failed to formulate correctly their perception about when this must be used, when this should be used, and when this should not be used. They also failed to correctly give a direct definition of what this is. This manifested mainly in the analysis of questions 1a, 2a, 2b, 5a–5c.

  7. 7.

    There is confusion between the visible object and the “invisible” object this—Students expressed misconceptions in the context of object visibility, from being visible using a particular identifier to being hidden or noted by the this notation. This manifested mainly in the analysis of questions 1c, 3.

  8. 8.

    The term this can be used in the main method—Students expressed a misunderstanding of the target and rule of the main method, and some believed that it was an instance method. This manifested mainly in the analysis of question 1d.

  9. 9.

    The compiler knows what this is—Students overestimate the capabilities of the compiler and believe that it understands the intentions of the programmer and thus knows by itself where to use this when the programmer avoids it. This manifested mainly in the analysis of question 1a.

The above nine inaccurate perceptions and misconceptions have not been reported in previous research. The most prevalent misconception, No. 1 in the list above, is connected to the encapsulation principle of OOP, which is mentioned in previous studies but has not been reported in relation to the current object using the notation this.

5.3 Answers to the research questions

Research question 1

Do students recognize where this must or must not be used in a given code? And which justifications do they provide? Most students understand the necessity of this in constructors when there is a need to distinguish between attributes of parameters, as revealed in the answers to question 1. In other contexts, a significant number of students expressed confusion and misunderstandings, as noted in misconceptions 4, 5, 6, 8, 9 above.

Research question 2

What are students’ personal preferences regarding the use of this, and what reasons do they provide? Most students preferred the traditional use of this in constructors. Moreover, since this is the form students became familiar with, most of them preferred to keep the same structure even when the this was not needed. This was expressed directly in students’ answers to question 2. The lack of success in other questions, with less common use of this, supports this claim as well. Those findings are expressed in misconceptions 4, 5, 6, 9.

Research question 3

How do students understand the execution of program statements when using this in different contexts? It appears that the students were less familiar with various contexts where this could be used. It was expected that students would grasp the essential conception of this—knowledge that should enable them to transfer the principles to new contexts—but they failed. Those findings are expressed in misconceptions 1, 5, 7, 8, 9.

Research question 4

How do students conceptualize their understanding of the this concept? Most of the students failed to formulate clear rules for when this must, should, or should not be used, according to question 5 findings. In relation to the question “What is this?” only 40% of the HS students and 38% of the CE students indicated that this was the current object on which a particular method was called. Others mixed up different OOP concepts, reduced the meaning of this. Those findings are expressed in misconceptions 2, 3, 4, 5, 6, 7.

Research question 5

What are the differences between high school students and college students of engineering regarding the conception of this? As is evident from the analysis of the findings, there is no clear conclusion regarding the differences between the two groups of participants. In relation to question 1a, while in most clauses the CE students were significantly better at giving correct answers, their explanations still expressed similar misunderstandings. In question 1b, CE students met greater success, while HS students generalized their answers more. In question 1c, CE students did significantly better omitting the use of this in the static method, but HS students did significantly better at addressing three of the needed changes together. Apparently, in general, students’ conceptions regarding this are similar, as expressed in question 5. The top three most frequent definitions were similar. In both groups about 40% of the students gave a correct definition, “the current object”; in both groups the second most frequent answer was “referral to attribute”; and the third was “referral to method,” with no significant differences. Those findings are expressed in misconceptions 1, 2, 3.

5.4 Mapping the findings in relation to the research

In Table 10 presented in Appendix 2 we map the characterized misconceptions in relation to the diagnostic tool questions, the research questions, and the different usages of this. In addition to the mapping of the misconceptions to the diagnostic tool questions and the mapping of the answers to the research questions to the misconceptions, we interpret how the misconceptions can be expressed in relation to the different usages of this as presented in the background.

For example, misconception 1, “this is not an object”, can be indicated in students’ answers to question 1 clause b and to question 3. The indication of this misconception allows us to answer research questions 3 and 5. This misconception might be expressed in using this in common usages numbers 1 and 4.

The mapping can support educators’ use of the diagnostic tool in relation to a learned subject in the sense of being aware of the conceptions, misconceptions, and difficulties students face. This leads to our recommendations for teaching.

6 Recommendations for teaching

On the basis of research findings and our experience teaching OOP, we have developed several recommendations for instructional scaffolding to prevent student misconceptions in relation to the this reference. They are as follows:

  1. a.

    Present students with code snippets that contain the this reference in various contexts and discuss when this should be used and when it should not be used, and why. For example, use different codes for constructors.

  2. b.

    Incorporate diagnostic open-ended questions to allow recognition of students’ conceptions and misconceptions regarding the this reference. For example, could this be used in the main method? What is this? To what does the this refer?

  3. c.

    Use this incorporated with various topics that express different levels of abstraction: for example, in composed classes, as a parameter, and using overloaded constructors. We recommend not restricting the use of this to when instance variables and method parameters have the same identifiers.

  4. d.

    Use visual tools that illustrate the program execution. These tools enable visualization of the processes involved in object creation, executing the constructor method, and invoking other methods. Furthermore, they can support students in the transition between the visible object to its invisible form using this.

  5. e.

    Use our questionnaire as a tool for learning. Educators can use it as an inquiry task so students can examine their own understanding, check and run the codes on a computer, and reduce the gap between what they currently understand and more accurate knowledge. This experience enables students to interact with the concepts through practical programming, as well as interacting theoretically.

  6. f.

    Use trace tables of objects. Educators need to adopt a way to represent object tracing. In particular, graphically show the reference to an object and how it serves as this when executing internal methods with both simple and composed objects.

  7. g.

    Emphasize the meaning of encapsulation in OOP. If students grasp the sense of the object as a capsule, it will be easier for them to understand its inner notation this and its functions.

  8. h.

    Continue discussion on the conceptual level, above programming aspects, to foster accuracy and refinement of the understanding. For example, refer to the current object when relating to attributes and internal methods, even when not using the this notation.

Using visual environments enables to emphasize all the above recommendations as a base for class discussions, while letting students do enquiry and diagnostic assignments. Figures 1 and 2 present illustrations from two free and known environments, the Jeliot visual memory and execution debugger (Jeliot n.d.) and the BlueJ visual class diagram and objects interaction (BlueJ n.d.).

Fig. 1
figure 1

Jeliot Illustration of a Simple Class Point and a Composed Class Line

Fig. 2
figure 2

BlueJ Illustration of a Simple Class Point and a Composed Class Line

Both environments emphasize the reference to objects by using an arrow, which comprises the encapsulation aspect of objects. Understanding encapsulation is the basis for understanding the this reference and its different usages in code. The Jeliot (n.d.) environment, as a visual debugger, enables one to follow the execution of codes comprising this.

7 Summary

This paper presents research conducted with high school students (N = 86) and college engineering students (N = 77) learning OOP. The focus was on students’ understanding of the this reference, since proper conceptualization of this indicates an understanding of objects in general and of the current object in particular. A diagnostic questionnaire was developed to directly expose students’ perceptions and misconceptions regarding the current object in different contexts. It was written in Java but can be translated into any OOP language. The different questions highlight wide and varied aspects of the use of this, which reflect the understanding of the “object” concept. Some questions were related to basic aspects, while others involved new ideas and advanced aspects. The questions reflect high-order cognitive skills according to Bloom’s taxonomy (Bloom 1956); most of them require analysis, synthesis, and evaluation. The research addresses the students’ perspective in learning programming, in particular students’ thinking processes, code literacy, behavior, ability, and attitudes, as was mapped in the latest systematic literature review of introductory programming (Luxton-Reilly et al. 2018).

The results reveal that most of the students did not express a meaningful understanding about the current object and its usage in various scenarios. It appears that various core OOP concepts are involved when relating to the meaning of the current object, noted by the reserved word this. Although this can apparently be viewed as “just a notation,” its use distorted correct conceptions, as well as causing misconceptions. It was observed that some students correctly related to the operative approach of using this, although they did not necessarily show evidence of a meaningful understanding of it. In general, students preferred and were accustomed to using this mainly in constructors methods, particularly in the traditional parameter constructor that bears the same identifier names as attributes. On the basis of our findings, we characterized nine misconceptions that can serve educators in their teaching and learning processes.

Attention should be given to students’ conceptions that depend not only on their understanding but also on conventions used in class and on personal preferences. It is recommended that educators address the meaning of the current object this alongside the teaching–learning processes and keep the conceptual level above all the practical programming aspects. We believe that addressing complex and non-trivial questions, which do not usually appear in learning materials, will result in accuracy and refinement of the students’ understanding. Since the concept of “object” is known to be abstract and difficult to grasp, as many previous studies have noted, direct discussion about it in the teaching process is recommended. A better understanding of “object” in general may lead to a better understanding of the this reference in particular. Educators can use the presented diagnosis tool as a class exercise and can follow the recommendations and implement them in their classes.