Tutorial 13: Multilevel Inheritance in Java
Code:
Computer.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MultilevelInheri;
/**
*
* @author Ankit
*/
public class Computer {
private int totalUSBPorts;
private int totalRAMinGBs;
public void start(){
System.out.println("yes i can start!!!");
}
public void shutdown(){
System.out.println("yes i can shutdown!!!");
}
public int getTotalRAMinGBs() {
return totalRAMinGBs;
}
public void setTotalRAMinGBs(int totalRAMinGBs) {
this.totalRAMinGBs = totalRAMinGBs;
}
public int getTotalUSBPorts() {
return totalUSBPorts;
}
public void setTotalUSBPorts(int totalUSBPorts) {
this.totalUSBPorts = totalUSBPorts;
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MultilevelInheri;
/**
*
* @author Ankit
*/
public class Computer {
private int totalUSBPorts;
private int totalRAMinGBs;
public void start(){
System.out.println("yes i can start!!!");
}
public void shutdown(){
System.out.println("yes i can shutdown!!!");
}
public int getTotalRAMinGBs() {
return totalRAMinGBs;
}
public void setTotalRAMinGBs(int totalRAMinGBs) {
this.totalRAMinGBs = totalRAMinGBs;
}
public int getTotalUSBPorts() {
return totalUSBPorts;
}
public void setTotalUSBPorts(int totalUSBPorts) {
this.totalUSBPorts = totalUSBPorts;
}
}
Laptop.java
package MultilevelInheri;
/**
*
* @author Ankit
*/
public class Leptop extends Computer{
private int totalBettryCells;
public int getTotalBettryCells() {
return totalBettryCells;
}
public void setTotalBettryCells(int totalBettryCells) {
this.totalBettryCells = totalBettryCells;
}
}
/**
*
* @author Ankit
*/
public class Leptop extends Computer{
private int totalBettryCells;
public int getTotalBettryCells() {
return totalBettryCells;
}
public void setTotalBettryCells(int totalBettryCells) {
this.totalBettryCells = totalBettryCells;
}
}
MacBook.java
package MultilevelInheri;
/**
*
* @author Ankit
*/
public class MacBook extends Leptop{
}
/**
*
* @author Ankit
*/
public class MacBook extends Leptop{
}
MultiInheri.java
package MultilevelInheri;
/**
*
* @author Ankit
*/
public class MainInheri {
public static void main(String[] args) {
MacBook myMacBook = new MacBook();
myMacBook.setTotalBettryCells(9);
myMacBook.setTotalRAMinGBs(8);
myMacBook.setTotalUSBPorts(4);
System.out.println("my macbook is equipted with "+myMacBook.getTotalBettryCells()+"bettry Cells");
System.out.println("my macbook is equipeted with "+ myMacBook.getTotalRAMinGBs()+"RAM");
System.out.println("my macbook is equ with "+ myMacBook.getTotalUSBPorts()+"USBs");
}
}
/**
*
* @author Ankit
*/
public class MainInheri {
public static void main(String[] args) {
MacBook myMacBook = new MacBook();
myMacBook.setTotalBettryCells(9);
myMacBook.setTotalRAMinGBs(8);
myMacBook.setTotalUSBPorts(4);
System.out.println("my macbook is equipted with "+myMacBook.getTotalBettryCells()+"bettry Cells");
System.out.println("my macbook is equipeted with "+ myMacBook.getTotalRAMinGBs()+"RAM");
System.out.println("my macbook is equ with "+ myMacBook.getTotalUSBPorts()+"USBs");
}
}
No comments:
Post a Comment