Thursday, March 31, 2016

Many Methods & Instance

Hey guys, welcome to another java tutorial. In this post we're gonna learn about Multiple Methods and Instance.


  • First step, clear all the codes in the main class & the sub class.
  • OK it's done right? Well this time we're gonna something weird. Yeah, you're gonna display your name & your first girlfriend name on the screen.  
  • First step clear all old coding in main & sub_clz classes
In the Sub_clz
  • Go ahead & declare two variable.
You can I've put "private" before the variable. That because, we wanna use these variables only in this class. If put the " public" you will be able to use it in other classes too.
  • Create a method to get the names 


This method, it has two parameters and these variable has been equaled variable that declared before. OK What're the values of these parameters. From where they come? That's call patience... Hahaa just kidding.. Look forward to it. 

  • Another two methods to return the names


After it you have to return those values.

  • Last one to print the names on the screen


Print it. But there's little bit of difference. there's ''printf " instead of "println" Well that's print function. In print function you can print variables with the string(text in simple).

In the main class
  • Create two scanners
  • Create a sub_clz object


  • Pass the values taken from scanner to [ getName ] method


  • Call the [ print ] method.

No comments:

Post a Comment