Interview Preparation (1/n)

  1. What interviewers are looking for in a candidate
  2. How the next question depends on your previous answer
  3. How you as a candidate can drive the interview instead of the interviewer
  1. What is your contribution to this project?
  2. What were your role and responsibility?
  3. If you had faced any challenges and how you overcame those.
  • You can declare a field in the subclass with the same name as the one in the superclass, thus hiding it (not recommended).
  • You can write a new instance method in the subclass that has the same signature as the one in the superclass, thus overriding it.
  • You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.
  • You can write a subclass constructor that invokes the constructor of the superclass, either implicitly or by using the keyword super.
class A
{
public void display()
{
System.out.println("class A display");
}

public static void show()
{
System.out.println("class A show");
}
public void print()
{
System.out.println("class A print");
}
}class B extends A
{
public void display()
{
System.out.println("class B display");
}
public static void show()
{
System.out.println("class B show");
}
public int print()
{
System.out.println("class B print");
return 0;
}
}
public class MainClass{public static void main(String []args){

B b = new B();
A b1 = new B();
b.show();
b1.show();
b.display();
b1.display();
}
}
  1. If function print is valid overriding?
class B show
class A show
class B display
class B display

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store