Wednesday, February 27, 2013

Important Notes


  1. ALL METHOD IMPLEMENTS FROM INTERFACE MUST BE DECLARED AS PUBLIC



2. ClassName(){ super(){}} is added automatically if there is no programmer-defined constructor.
QUESTION NO: 88
Given:
1. public class Plant {
2. private String name;
3. public Plant(String name) { this.name = name; } //if (Plant has no Constructor) JVM  add Plant(){ super(){} } automatically;

4. public String getName() { return name; }
5. }


1. public class Tree extends Plant { 
//Tree(){ super(){} } was added automatically.
2. public void growFruit() { }
3. public void dropLeaves() {}  
4. }

The code will compile if public Plant() { this("fern"); } is added to the Plant class.


No comments:

Post a Comment