Compare the Difference Between Similar Terms

Difference Between

Home / Technology / IT / Programming /Difference Between Attribute and Parameter

Difference Between Attribute and Parameter

April 1, 2018Posted byLithmee

Key Difference – AttributevsParameter

Thekey difference属性之间and parameter is thatan attribute is a variable of any type that is declared directly in a class while a parameter is a variable defined by the function that receives a value when it is called.

In programming languages such as Java, there are concepts likeobjects, classesand功能. When coding, the programmer should follow the specific syntax related to the programming language. An attribute is used with classes and objects while a parameter is used with functions or methods. This article discusses the difference between attribute and parameter.

CONTENTS

1.Overview and Key Difference
2.What is Attribute
3.What is Parameter
4.Side by Side Comparison – Attribute vs Parameter in Tabular Form
5.Summary

What is Attribute?

Programming languages such as Java supports Object Oriented programming. This programming paradigm is based on objects. An object has a state and behaviour. The state is represented by the data values. They are also called as fields or attributes. The behaviour or the functionality is represented by methods. A class is a blueprint to create an object. Therefore, an object is an instance of a class. A student object can hav e attributes such as student id and name. An Employee can have attributes such as employee ID, name, salary and department. An Animal object can have attributes such as name, favourite food etc.

Difference Between Attribute and Parameter

Figure 01: Java Program with Attributes

According to the above program, the Rhombus class has two attributes that are diagonal1 and diagonal2. It also has the constructor and a method to calculate the area. In the main program, an object of Rhombus is created. Two values are passed to the constructor, and those will assign to the diagonal1 and diagonal2 attributes. When calling the calArea method, the area of the Rhombus is calculated, and it will return the answer, which is a double value. Finally, the calculated area will print on the screen. The two diagonal values are the attributes of the class and of the object r1.

What is Parameter?

A Function is a major concept in programming. It is a set of statements to perform a specific task. Functions increase code reusability. There can be predefined functions provided by the programming language. The programmer can also write his own functions. They are called as user-defined functions. The term parameter is associated with the function. A parameter is similar to a place holder. The syntax of the function is as follows.

<(parameters)> {

// function code

}

The access modifier represents the visibility of the method. It can be private, public etc. A private method is accessible within the class. A public method is accessible by all the classes. The return type defined the output from the function. If it is an integer, the return type is int. If it is a double value, then the return type is double. If the function does not return anything, it is declared as void. The function name is the actual name of the function to identify it. The parameters are the variables defined by the function that receives the values when the function is called. The function code is placed inside the curly braces.

Key Difference Between Attribute and Parameter

Figure 02: Java Program with Parameters

According to the above program, the length and width values are passed into the calArea function. In statement calArea (length, width); the length and width are arguments. In the function definition, there is calArea (int a, int b); The length value is copied to variable ‘a’ and width value is copied to variable ‘b’. These ‘a’ and ‘b’ are parameters. The argument values are copied to parameters when the function is called. The calculated area is returned from calArea. The result is assigned to the variable area in the main program. Finally, the area of the rectangle is printed.

What is the Difference Between Attribute and Parameter?

属性和参数

An attribute is a variable of any type that is declared directly in a class. A parameter is a variable defined by the function that receives a value when it is called.
Usage
An attribute is used with classes and objects. A parameter is used with a function or a method.

Summary – AttributevsParameter

Attribute and parameter are two terms associated with programming. This article discusses the difference between attribute and parameter. The difference between attribute and parameter is that an attribute is a variable of any type that is declared directly in a class while a parameter is a variable defined by the function that receives a value when it is called.

Reference:

1.“Java Object and Classes.”,Tutorials Point, 24 Mar. 2018.Available here

Related posts:

Difference Between Argument and ParameterDifference Between Argument and Parameter Difference Between Abstract Class and Interface Difference Between Static Binding and Dynamic BindingDifference Between Static Binding and Dynamic Binding Difference Between append and extend in PythonDifference Between append and extend in Python Difference Between float and double_Figure 02Difference Between float and double

Filed Under:ProgrammingTagged With:attribute,Attribute and Parameter Differences,Attribute and Parameter Similarities,Attribute Definition,Attribute Usage,属性和参数,Compare Attribute and Parameter,Parameter,Parameter Definition,Parameter Usage

About the Author:Lithmee

Lithmee <是一个大麻(荣誉)在计算机毕业ter Systems Engineering. She is currently pursuing a Master’s Degree in Computer Science. Her areas of interests in writing and research include programming, data science, and computer systems.

Leave a ReplyCancel reply

Your email address will not be published.Required fields are marked*

Request Article

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and SARS

Difference Between Coronavirus and SARS

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

You May Like

Difference Between Tartan and Plaid

Difference Between Salon and Saloon

Difference Between Lawyer and Advocate

Difference Between Lawyer and Advocate

Difference Between Parallels and Meridians

Difference Between Parallels and Meridians

Difference Between Grassland and Savanna

Latest Posts

  • What is the Difference Between Molecular Formula and Structural Formula
  • What is the Difference Between Acne and Eczema
  • What is the Difference Between Mutation Rate and Substitution Rate
  • What is the Difference Between Vermicompost and Compost
  • What is the Difference Between Depression and Schizophrenia
  • What is the Difference Between Molecular Geometry and Electron Geometry
  • Home
  • Vacancies
  • About
  • Request Article
  • Contact Us

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Useand Privacy Policy:Legal.