About Question enthuware.ocajp.i.v7. 2 . 1220 :
Moderator: admin
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
About Question enthuware.ocajp.i.v7. 2 . 1220 :
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static field b
at TestClass.C.main(C.java:18)
Sir, can you please make changes for the above program to access "i" declared in class B!
Cannot make a static reference to the non-static field b
at TestClass.C.main(C.java:18)
Sir, can you please make changes for the above program to access "i" declared in class B!
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
I have no idea what you are trying to do. Please read the detailed explanation given with the question carefully. Also, my comment above explains exactly how you can access b's i.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
I have tried, B b = new B();admin wrote:I have no idea what you are trying to do. Please read the detailed explanation given with the question carefully. Also, my comment above explains exactly how you can access b's i.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1220 :
You have some problem in your environment. Please fix that issue first. If you are using any IDE, please don't use it. Just use the command line.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7. 2 . 1220 :
This is the code that I am trying to compile,
And yes I am using IDE.
class A{
private int i = 10,j=0;
public void f(){}
public void g(){}
}
class B extends A{
public int ib = 20;
public void g(){}
}
public class C{
A a = new A();//1
B b = new B();//2
public static void main(String[] args) {
System.out.println(b.ib);
}
}
And yes I am using IDE.
class A{
private int i = 10,j=0;
public void f(){}
public void g(){}
}
class B extends A{
public int ib = 20;
public void g(){}
}
public class C{
A a = new A();//1
B b = new B();//2
public static void main(String[] args) {
System.out.println(b.ib);
}
}
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7. 2 . 1220 :
As I said, stop using IDE. Use the command line.
I have removed your message about compilation issue from other thread because it has nothing to do with that question.
I have removed your message about compilation issue from other thread because it has nothing to do with that question.
-
- Posts: 32
- Joined: Sat May 02, 2015 11:57 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7. 2 . 1220 :
Code: Select all
class A
{
private int i = 10,j=0;
public void f(){}
public void g(){}
}
class B extends A
{
public int ib = 20;
public void g(){}
}
public class C
{
A a = new A();//1
B b = new B();//2
public static void main(String[] args)
{B b = new B(); System.out.println(b.ib);}
}
Who is online
Users browsing this forum: No registered users and 6 guests