What's new

Closed Question Java

Status
Not open for further replies.

Carly_Rose

Eternal Poster
Joined
Dec 8, 2018
Posts
1,289
Reaction
245
Points
348
Hello mga ka PHC in you're own opinion tagalog way hehehehe ano po ba purpose ng constructor sa java at ang parameter neto at method with parameter salamat po sa mga makakatulong medyo nalilito po kasi ako.
 
Constructor - para makapag create ka ng object na magagamit mo sa main sa syempre sa ibang class din.
kapag nakapag create ka na ng object magagamit mo na yung mga ginawa mong method sa loob ng class.
Parameter sa Contructor - pwede kang hindi na maglagay o kung meron man, ginagamit naman yan para ipasa yung value nung parameter sa field.
 
Method in Java
Code:
class phc 
{
    int getProd(int x, int y)
    {
        return x * y;
    }
    static void main(String[] a)
    {
        print("6 x 7 = " + getProd(6, 7)); //yun 6 and 7 arguments or data na ipapasa sa method na ma received ni parameter x, y
    }
}

para sa function ang method to avoid redundancy sa code para hindi mo palagi itype like sum = x + y

int is a keyword or data types & getProd naman ang method while parameter is yun tagasapo ng data na pinasa ni main which is 6 & 7
 
Constructor - para makapag create ka ng object na magagamit mo sa main sa syempre sa ibang class din.
kapag nakapag create ka na ng object magagamit mo na yung mga ginawa mong method sa loob ng class.
Parameter sa Contructor - pwede kang hindi na maglagay o kung meron man, ginagamit naman yan para ipasa yung value nung parameter sa field.
Salamat po sa pag reply kuya sobrang appreciated po.
 
Method in Java
Code:
class phc
{
    int getProd(int x, int y)
    {
        return x * y;
    }
    static void main(String[] a)
    {
        print("6 x 7 = " + getProd(6, 7)); //yun 6 and 7 arguments or data na ipapasa sa method na ma received ni parameter x, y
    }
}

para sa function ang method to avoid redundancy sa code para hindi mo palagi itype like sum = x + y

int is a keyword or data types & getProd naman ang method while parameter is yun tagasapo ng data na pinasa ni main which is 6 & 7
Thanks po kuya sa pag reply appreciated much.
 
We use constructor to initialized all the class/object member upon creation. One of the specific scenario is when you are trying to access/pass a class variable's value to/from the other class. You usually write something like: MyClass(Object obj) where obj as object/class is used as a parameter to initialized its member. All publicly declared variable or other member inside obj class will be accessible and can be utilized inside MyClass class. Access it something like : obj.myVariable.

Methods on the other hand is a blocks of codes that has a specific function within the class or an entire solution. Use for the benefit of code reuse(supposed we have the same task to perform from different places). It is also used to encapsulate a certain algorithm to other class or methods. Parameterized Methods are just a Method accepting values from elsewhere(from it's caller) that is used to it's function's result. Some Methods has the ability to return a certain parameter's value by using 'Out Parameter'. Parameters can be of any typed too. Would it e an object, any types of variables, array, etc. Some methods do not transmit or return anything(void) but to only process some tasks.
 
Status
Not open for further replies.

Similar threads

Back
Top