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

For ****JAVA**** In this assignment you will design a program that creates a cla

ID: 3855061 • Letter: F

Question

For ****JAVA****

In this assignment you will design a program that creates a class, then extends the class using Inheritance. You may pick any base class, such as car, bike or television. Then you must extend the class at least once. Must be compiled as one Java file

import java.io.PrintStream;

public class Sub_class
extends Super_class
{
int num = 10;
  
public void display()
{
System.out.println("This is the display method of subclass");
}
  
public void my_method()
{
Sub_class sub = new Sub_class();
  
sub.display();
  
super.display();
  
System.out.println("value of the variable named num in sub class:" + sub.num);
  
System.out.println("value of the variable named num in super class:" + this.num);
}
  
public static void main(String[] args)
{
Sub_class obj = new Sub_class();
obj.my_method();
}
}

Explanation / Answer

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

____________________

Bike.java

//Declaring super class named Bike
public class Bike {

//Default constructor
public Bike() {
System.out.println(":: This is Super class Constructor ::");
}

//method1
public void method1() {
System.out.println(":: This is Super class Method 1 ::");
}

}

____________________

BajajPulser.java

//BajajPulserr class is the sub class of Bike class
public class BajajPulser extends Bike {

//Default constructor
public BajajPulser() {
System.out.println(":: This is sub class constrctor ::");
}

//Overriding the method in the super class.
@Override
public void method1() {
System.out.println(":: This is Sub class Method 1::");
super.method1();
}

//Writing the method2()
public void method2() {
System.out.println(":: This is Sub class Method 2::");
}
}

_______________________

TestClass.java

public class TestClass {

public static void main(String[] args) {
//Creating An object to the Subclass (BajajPulser)
BajajPulser bp = new BajajPulser();

//Calling the method1() on the subclass object
bp.method1();

//Calling the method2() on the subclass object
bp.method2();

}

}

______________________

Output:

:: This is Super class Constructor ::
:: This is sub class constrctor ::
:: This is Sub class Method 1::
:: This is Super class Method 1 ::
:: This is Sub class Method 2::

_____________Thank You

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