r/javahelp • u/lightprojector • Apr 20 '20
Inheritance question
This is the code the professor gave us and I have no idea what to do with it. He wants me to print out i and j. I've tired changing a few things but I don't understand the code in general and I am always getting an error in class inherited. I tried changing "class B extends A" to "class B extends Inheritance" and this gets rid of that error but at the "System.out.println(obj.i + " " + obj.j);" there's always an error with i&i that states they cant find them. I named the super class Inheritance and the subclass inherited btw. Thank you ahead of time for any help.
class A
{
public int i;
public int j;
A()
{
i = 1;
j = 2;
}
}
class B extends A
{
int a;
B()
{
super();
}
}
class super_use
{
public static void main(String args[])
{
B obj = new B();
System.out.println(obj.i + " " + obj.j);
}
}
5
u/GuyWithLag Apr 20 '20
First of all, you're asking us to donate some of our time, but haven't donated your time; please be considerate:
format the code (yes, that is possible even with reddit's weird editor.
clearly state a) the problem, b) what you want to achieve c) what you have tried so far.