Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design two programs named BaseClass arid Subclass. In BaseClass, define a variab

ID: 3777836 • Letter: D

Question

Design two programs named BaseClass arid Subclass. In BaseClass,  define a variable xVar (type: char, value: 65),  and a method myPrint to print xVar. SubClass is a subclass of BaseClass. In Subclass,  define a variable yVar (type: int, value: 16) and another variable strVar (type: String, value: "java program!"). There is also a method myPrint to print the value of yVar and strVar in SubClass,  as well as an additional method printAll, in which invoking myPrint method both from the base class and sub class. Write a test program. In the main method, declare an instance of SubClass named bObj. Then use the object to call method printAII to output all the properties of that object. ** Provide the source code.

Explanation / Answer

BaseClass.java

public class BaseClass{
    char xVar = 65;

    void myPrint(){
        System.out.println(this.xVar);
    }

}

SubClass.java

public class SubClass extends BaseClass{
    int yVar = 16;
    String strVar = "java program!";

    void myPrint(){
        System.out.println(this.yVar);
        System.out.println(this.strVar);
    }

    void printAll(){
        myPrint();
        super.myPrint();
    }
}

DriverClass.java

public class DriverClass{
    public static void main(String[] args) {
        SubClass bObj = new SubClass();
        bObj.printAll();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote