Questions And Correct Answers |Graded
A+|
Which of the following could be used to instantiate a new Student s1?
a) new Student(s1);
b) new Student s1 = ("Jane Doe", "Computer Science", 3.333, 33);
c) Student s1 = new Student("Jane Doe", "Computer Science", 3.333, 33);
d) Student s1 = new Student( );
e) s1 = new Student( ); - ANSWER -c) Student s1 = new Student("Jane Doe",
"Computer Science", 3.333, 33);
Consider a method defined with the header: public void foo(int a, int b). Which of
the following method calls is legal?
a) foo(, 2 * 3);
b) foo(0, 0.1);
c) foo(0);
d) foo(1 + 2, 3 * 0.1);
e) foo( ); - ANSWER -a) foo(, 2 * 3);
Use the following partial class definitions:
public class A1
{
public int x;
private int y;
protected int z;
...
}
public class A2 extends A1
{
protected int a;
, private int b;
...
}
public class A3 extends A2
{
private int q;
...
}
Which of the following is true with respect to A1, A2 and A3?
a) A2 and A3 are both subclasses of A1
b) A1 and A2 are both subclasses of A3
c) A1 is a subclass of A2 and A2 is a subclass of A3
d) A3 is a subclass of A2 and A2 is a subclass of A1 - ANSWER -d) A3 is a
subclass of A2 and A2 is a subclass of A1
Use the following partial class definitions:
public class A1
{
public int x;
private int y;
protected int z;
...
}
public class A2 extends A1
{
protected int a;
private int b;
...
}
public class A3 extends A2
{
private int q;
...
}
,Which of the following lists of instance data are accessible in class A2?
a) z, a, b
b) x, y, z, a
c) x, y, z, a, b
d) a, b
e) x, z, a, b - ANSWER -e) x, z, a, b
Use the following partial class definitions:
public class A1
{
public int x;
private int y;
protected int z;
...
}
public class A2 extends A1
{
protected int a;
private int b;
...
}
public class A3 extends A2
{
private int q;
...
}
Which of the following lists of instance data are accessible in A3?
a) x, z, a, q
b) x, y, z, a, b, q
c) a, q
d) x, a, q
e) a, b, q - ANSWER -a) x, z, a, q
, Use the following partial class definitions:
public class A1
{
public int x;
private int y;
protected int z;
...
}
public class A2 extends A1
{
protected int a;
private int b;
...
}
public class A3 extends A2
{
private int q;
...
}
Which of the following is true regarding the use of instance data y of class A1?
a) it is accessible in A1 and A2
b) it is accessible in A1, A2 and A3
c) it is accessible only in A3
d) it is accessible only in A1
e) it is not accessible to any of the three classes - ANSWER -d) it is accessible
only in A1
All classes in Java are directly or indirectly subclasses of the _______ class.
a) Object
b) this
c) Reference
d) String
e) Wrapper - ANSWER -a) Object