Hi, I'm new to java but have some experience with C++ can anyone help me with a basic code to display inheritance? I'v chosen a Parent class Phone and a Child class Mobile and I want to simply use the display method from my parent class on the child class.
here is my code:
public class Phone {
protected int num; // parent state
public Phone(int a)
{num = a;} // constructor
public void display() {
System.out.println("The Phone has the number " + num);
}
}
public class Mobile extends Phone {
private String model;
public Mobile(int a,String s){
super(a); //call parent constructor
model = s;
}
public static void main(String[] args)
{
Mobile a = new Mobile(454666,"nokia");
a.display();
}
}