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

3.11 True or False? It is legal in a class for a method to override another meth

ID: 3848061 • Letter: 3

Question

3.11 True or False? It is legal in a class for a method to override another method also in the same class. Explain.

3.12 True or False? It is legal in a subclass for a method to overload a method in the superclass. Explain.

3.13 True or False? It is legal in a subclass for a method to override a method in the superclass. Explain.

3.14 True or False? It is legal in a superclass for a method to overload a method in a subclass. Explain.

3.16 In a subclass constructor, the superclass default constructor is called automatically before the statements of the subclass constructor begin executing. Suppose we wish to call a different superclass constructor (i.e., not the default constructor) from the subclass constructor. Explain how this is accomplished and give an example.

Explanation / Answer

3.11)Answer is false. It is not legal in a class for a method to override another method also in the same class.

public class House {
public void met1()
{
   System.out.println("RUNNING..");
}
public void met1()
{
   System.out.println("RUNNING safely..");
}
}
public static void main(String[] args)
{
   House h=new House();
   h.met1();
}

here in the above program it shows compile time error because the same method cannot be overriden in a class.
3.12)Answer is true.It is legal in a subclass for a method to overload a method in the superclass. The example java programming code is

class House {
public void hello() {
   System.out.println("hello method");
}
}

class C extends House {
public void hello(String s) {
   System.out.println("hello method overloading"+s+" ");
}
   public static void main(String[] args)
   {
       C c=new C();
       c.hello();
       c.hello("home");
}
}

the output is

hello method

hello method over

3.13) True.  It is legal in a subclass for a method to override a method in the superclass.

class House {
public void hello() {
   System.out.println("hello method");
}
}

class C extends House {
public void hello() {
   System.out.println("hello method overriding");
}
   public static void main(String[] args)
   {
       C c=new C();
       c.hello();
         
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote