Code Snippets in JAVA Programming and their OUTPUTS-Day 2
CODE SNIPPETS OUTPUT
CONSTRUCTORS
Concept: Constructors – special methods with no return types
class General
{
General()
{
System.
out.
println("General constructor called");
}
}
class Test
{
public...
More
Code Snippets in JAVA Programming and their OUTPUTS-Day 2
CODE SNIPPETS OUTPUT
CONSTRUCTORS
Concept: Constructors – special methods with no return types
class General
{
General()
{
System.
out.
println("General constructor called");
}
}
class Test
{
public static void main (String [] args)
{
General g=new General();
}
}
General constructor
called
Question: Can constructors be private? Answer: Yes
class Test
{
private Test()
{
System.
out.
println("Test constructor");
}
public static void main (String [] args)
{
Test constructor
Less