Thursday, August 26, 2021

# 12. non static method

 non-static method:

whenever the business implementations are not constant then we go for the non-static method.

standard syntax:

1. <access specifier>    void      methodname()

{

;;;;;;;;;;;;;;;;;;;;;;;

}

2. <access specifier> return type methodname()

{

;;;;;;;;;;;;;;;;;;;;;;;

return <statement>;

}

BR: WAP for the addition of 2 numbers

45+45=90

/* using void type

public class Addition_Program{

int num1=45;

int num2=45;

public void addition_Program()

{

int result=num+num2;

}

}

/* Using return type:

public class Addition_Program{

int num1=45;

int num2=45;

public int addition_Program()

{

int result=num+num2;

return result;

}

}

float, long, double are valid because they are higher than int

byte short is invalid.


No comments:

Post a Comment

# 16. control statements

 Control statements: In java, by using control statements we can tell the flow of execution. in which order the statements should execute. d...