0% found this document useful (0 votes)
18 views

Parameters and Overloading Methods Final

Uploaded by

dddsssoff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Parameters and Overloading Methods Final

Uploaded by

dddsssoff
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Hallo, our name is Group 2!

Parameters and
Overloading
methods
Methods

They are chunks of


Parameters
code grouped into a Return Type
Method name
single place and they
can be executed
from one line by
calling its name.
Example & Demonstration

Data Type
Variable name
WHAT ARE PARAMETERS??
A parameter is a variable in a method declaration that
is passed to the method.

<Data Type> <Variable Name>


What is a Access modifier??

Access modifiers - are keywords which define the


accessibility of a class and its members. Access
modifiers are used in Java to control the visibility
(accessibility) of classes, interfaces, variables,
methods, constructors, data members, and setter
methods
Access Modifiers
public – allows access from anywhere. Classes and methods are
usually public. Use this keyword when it does not matter that
anyone can access your code or when you wish to share your
code with others.

private – allows access only from inside the same class. Fields
are usually private. Use private when it is important that your
code is secure.
protected – allows access inside the class, subclass, or
other classes of the same package as the modifier.

default – When private, public, or protected is not used.


Allows access only from inside the same package. To
declare a variable, method, or class as "default," do not
include an access modifier. A common mistake new Java
programmers make is to not specify an access modifier and
thus get the default.
Example of access modifiers

default
Example
Project
Structure
Variable Argument Method

A variable argument method is a


method written to handle a
variable number of arguments. It
only works if you call the method
with the same type of argument as
the method requires.
Variable Argument Method
What is overloading methods??

Overloading method - Is having


two or more methods (or
functions) in a class with the
same name but different
parameters (or arguments)
Example Output
Constructors

Constructors Allows you to


assign initial values to instance
variables of a class. Constructors
inside a class are declared like
methods.
Examples:
Constructors can
also be overload
just like overloading
a method
Quiz!!!!!!!!!
Quiz Time TRUE or FALSE
1. _______ Methods (aka Functions) are chunks of code grouped into a
single place and they can be executed from one line by calling its name.

2. _______ Parameters are variables or values in a method declaration


that is passed to the method.

3. _______ A private modifier allows access only from inside the same
class.

4. _______ A public modifier allows access from the public internet,


anyone on the internet can use your class, variables, or methods.
5. _______ Variable argument method is a method written to handle a
variable number of arguments, meaning as many arguments as
needed.

6. _______ Overloading method have 2 or more methods (or function


) in a class but different name and but the same arguments.
7 - 10. Pick the FOUR correct access modifiers in Java

int public String default const


import var protected include
function final func double private
Correct
Answers
to
Quiz
Quiz Time TRUE or FALSE
1. True Methods (aka Functions) are chunks of code grouped into a
single place and they can be executed from one line by calling its name.

2. True Parameters are variables or values in a method declaration that


is passed to the method.

3. True A private modifier allows access only from inside the same
class.

4. False A public modifier allows access from the public internet,


anyone on the internet can use your class, variables, or methods.
5. True Variable argument method is a method written to handle a
variable number of arguments, meaning as many arguments as
needed.

6. True Overloading method have 2 or more methods (or function )


in a class but different name and but the same arguments.
7 - 10. Pick the FOUR correct access modifiers in Java

int public String default const


import var protected include
function final func double private
that's all thank you for listening!

You might also like