• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Troubling with this code

 
Vimal Kumar Venugopal
Ranch Hand
Posts: 43
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package packA;

public class Beverage {
public static void main(String[] args) {
System.out.println("hi");
}
}
----------------------------------------------------
package packB;

import packA.Beverage;

class Tea extends Beverage {

}
--------------------------------------
and when i run Tea class..
I get the output as"hi"!!!

How does this happen??
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you extend a class you inherit all its members. i guess that includes main()
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic