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: 3855049 • 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, or television. Then you must extend the class at least once.

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.

______________________

Car.java


//Declaring super class named Car
public class Car {

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

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

}

_____________________

MaruthiCar.java

//MaruthiCar class is the sub class of Car class
public class MaruthiCar extends Car {

//Default constructor
public MaruthiCar() {
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 (MaruthiCar)
MaruthiCar mc = new MaruthiCar();

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

//Calling the method2() on the subclass object
mc.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