Object creation and call a method

Overview:

In this blog about creating and object, call a method and Method Parameters.

Creating an Object:

An object is created from a class. In Java, the new keyword is used to create new objects.

There are three steps when creating an object from a class −

  • Declaration − A variable declaration with a variable name with an object type.
  • Instantiation  − The ‘new’ keyword is used to create the object.
  • Initialization − The ‘new’ keyword is followed by a call to a constructor. This call initializes the new object.

Call a Method:

To call a method in Java, write the method’s name followed by two parentheses () and a semicolon;

In the following example, myMethod(), sandhiya.go();  is used to print a text (the action), when it is called. A method can also be called multiple times.

Java Method Parameters:

Parameters and Arguments:

Information can be passed to methods as parameter. Parameters act as variables inside the method.

Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.

When a parameter is passed to the method, it is called an argument.

Reference:

https://www.tutorialspoint.com/java/java_object_classes.htm#:~:text=So%20basically%2C%20an%20object%20is,used%20to%20create%20the%20object.

https://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

https://www.w3schools.com/java/java_methods_param.asp

https://javabeginnerstutorial.com/core-java-tutorial/java-method-parameter-and-argument/

Leave a comment

Design a site like this with WordPress.com
Get started