r/javahelp • • 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);

}

}

0 Upvotes

8 comments sorted by

View all comments

3

u/Camel-Kid 18 year old gamer Apr 20 '20

What exactly is the problem, what did the professor want you to do in the first place..

-2

u/lightprojector Apr 20 '20

Oh sorry about that. The question was to printout i and j.