Concept 1: can we write a method same name as constructor in class definition.
Exp: Yes we can write a method same name as constructor in java class definition.
Code :
Above code compile without Error
Exp: Yes we can write a method same name as constructor in java class definition.
Code :
package com.threadTest;
public class constructorTest {
public void constructorTest()
{
System.out.println("Inside the constructor");
return;
}
public static void main(String[] args)
{
constructorTest ct=new constructorTest();
}
}
public class constructorTest {
public void constructorTest()
{
System.out.println("Inside the constructor");
return;
}
public static void main(String[] args)
{
constructorTest ct=new constructorTest();
}
}
Above code compile without Error
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.