Q. Answer questions (i), (ii) and (iii) below: class A { // data/fields int a; p
ID: 3679831 • Letter: Q
Question
Q. Answer questions (i), (ii) and (iii) below:
class A
{
// data/fields
int a;
public int b;
private int c;
protected int d;
static private int e;
static public int f;
final int g=5;
// methods
void f1() { /* statements */ }
public void f2() { /* statements */ }
protected void f3() { /* statements */ }
private void f4() { /* statements */ } static public void f5() { /* statements */ }
final void f6(){ /* statements */ }
void f7()
{ /* (i): list all fields/methods in class A
that can be directly accessed here */
f1(); System.out.println("HHH");
}
}
class B {
public static void main(String[] argv) {
A objA = new A();
/* (iii): : list all fields/methods in class A that can be accessed using objA */
}
}
Explanation / Answer
i)
int a;
public int b;
private int c;
protected int d;
static private int e;
static public int f;
final int g=5;
// methods
void f1() { /* statements */ }
public void f2() { /* statements */ }
protected void f3() { /* statements */ }
private void f4() { /* statements */ } static public void f5() { /* statements */ }
final void f6(){ /* statements */ }
iii)
public int b;
static public int f;
public void f2()
static public void f5()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.