Example & Tutorial understanding programming in easy ways.

Can we define two methods in a class with the same name?

Yes, We can define two methods in a class with the same name but with different number/type of parameters. Which method is to get invoked will depend upon the parameters passed.

 

class Test {

public void print()

{

System.out.println("Print method without parameters.");

}

public void print(String name)

{

System.out.println("Print method with paramter");

}

public static void main(String args[]) {

Test t=new Test();

t.print();

t.print("pradeep");

}

}

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!