Java constructor
overloading
class Language
{
String name;
Language()
{
System.out.println("Constructor method called.");
}
Language(String t)
{
name = t;
}
public static void main(String[] args)
{
Language cpp = new Language();
Language java = new Language("Java");
cpp.setName("C++");
java.getName();
cpp.getName();
}
void setName(String t)
{
name = t;
}
void getName()
{
System.out.println("Language name: " + name);
}
}
class GrandParent
{
int a;
GrandParent(int a)
{
this.a = a;
}
}
class Parent extends GrandParent
{
int b;
Parent(int a, int b)
{
super(a);
this.b = b;
}
void show()
{
System.out.println("GrandParent's a = " + a);
System.out.println("Parent's b = " + b);
}
}
class Child
{
public static void main(String[] args)
{
Parent object = new Parent(8, 9);
object.show();
}
}
No comments:
Post a Comment