Reputation: 1
Here is my code; apparently I am missing main. Please help
class A {
A get(){return this;}
}
class B1 extends A{
B1 get(){return this;}
void message(){System.out.println("welcome to covariant return type");}
public static void main(String args[]){
new B1().get().message();
}
}
Upvotes: 0
Views: 78
Reputation: 184
Class A
public class A
{
public A get()
{
return this;
}
}
Class B1
public class B1 extends A
{
public B1 get()
{
return this;
}
public void message()
{
System.out.println("welcome to covariant return type");
}
}
Main method
public static void main(String[] args)
{
B1 b1 = new B1();
B1 b2 = b1.get();
b2.message();
}
If you write it out like this, it's a bit clearer for you and for others to read. The main
method should be enclosed in a class, but I separated it out so you can see each component of your code.
Upvotes: 1