Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

TRUE or FALSE a child class can directly access private elements of the parent c

ID: 3831165 • Letter: T

Question

TRUE or FALSE a child class can directly access private elements of the parent class True False TRUE or FALSE a child class inherits public members of its parent class and has direct access to these elements even though they aren't defined in the child class True False TRUE or FALSE The keyword super is used in a class to refer to its parent class. True False TRUE or FALSE. The keyword sub is used in a class to refer to a class' child class. True False A class that is used as a basis to create other classes is called a (n) ____. parent class derived class child class interface What Java keyword is used to create a class that inherits from another class? extends implements type Of instance Of is A inherits

Explanation / Answer

Ques1) False

A child class cannot access directly private element of parent class

Ques2) True

A child class inherit public members of parent class and has direct access to these elements even though they aren't defined in child class

Eg.)

class HelloWorld{
public int x;
public void abc(){
  
}
}

class b extends HelloWorld {
public void xyz(){
}
}

class test {
public static void main(String arr[]){
b b1 = new b();
b1.abc(); // access parent class public member function
b1.x=0;    // access parent class public member variables
}
}

Ques 3) True

The super keyword is used in class to refer to its immediate parent class members.

eg.) class Base{
String color="white";
}
class Child extends Base{
String color="black";
void printColor(){
System.out.println(color); //prints color of Child class
System.out.println(super.color); //prints color of Base class
}
}
class Test{
public static void main(String args[]){
Child d=new Child();
d.printColor();
}}

Ques4) False

There is no keyword like sub

Ques 5) Parent class

A class that is used a basis to create other classes is called parent class.

e g)

class A{
public int x;
public void abc(){
  
}
}

class B extends A { // Here class A is Parent class and acts as base for class B
public void xyz(){
}
}

Ques 6) extends keyword is used to create a class that inherits from another class