khirulnizam

Inheritance test Book2

Jan 29th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1.  
  2. public class Book2 {
  3. private String title;
  4. private int numPages;
  5.  
  6. public void setTitle(String text){
  7. title=text;
  8. }
  9. public String getTitle(){
  10. return title;
  11. }
  12.  
  13. public void setNumPages(int num){
  14. numPages=num;
  15. }
  16. public int getNumPages(){
  17. return numPages;
  18. }
  19. }
  20.  
  21.  
  22. public class Textbook extends Book2{
  23. private int gradeLevel;
  24. public void setGradeLevel(int grade){
  25. gradeLevel=grade;
  26. }
  27. public int getGradeLevel(){
  28. return gradeLevel;
  29. }
  30. }
  31.  
  32.  
  33. public class Demobook {
  34.  
  35. public static void main(String[] args) {
  36. // TODO Auto-generated method stub
  37. Textbook bookobj = new Textbook();
  38. bookobj.setTitle("Intro to Java");
  39. bookobj.setGradeLevel(11);
  40. bookobj.setNumPages(100);
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment