DEV Community

hema latha
hema latha

Posted on

2 class link method

1.create a class called Guna
2.have main method in it
3.create object Guna
4.call method pen.write(); method
5.outer main method write method definition

  1. print -- writing in pink colour

public class Guna {

public static void main(String[] args) {
    // TODO Auto-generated method stub
         Guna pen = new Guna();
         pen.write();
}
Enter fullscreen mode Exit fullscreen mode

public void write ()
{
System.out.println("writing in pink colour");
}
}
out put-- writing in pink colour
after create another class called Harish

  1. have a main method in it
  2. create object Guna
  3. method calling pen.write();
  4. print out put --(writing in pink colour)

package terminaltask;

public class Harish extends Guna {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Guna pen = new Guna();
    pen.write();
}
Enter fullscreen mode Exit fullscreen mode

}
out put -writing in pink colour

Top comments (0)