Method overriding technique in java
This is a question on method overriding just focus program outputs and find why?
class Automobile {
private String drive() {
return "Driving vehicle";
}
}
class Car extends Automobile {
protected String drive() {
return "Driving car";
}
}
public class ElectricCar extends Car {
@Override
public final String drive()
{
return "Driving electric car";
}
public static void main(String[] args)
{
Car car = new Car();
System.out.println(car.drive());
/*
* Automobile at=new Automobile(); System.out.print(at.drive());
* // Compilation Error
*/
final Car caru = new ElectricCar();
System.out.println(caru.drive());
}
}
Program Output
Driving car
Driving electric car
Example 2::
Let's see if another source code predicts give
what will be output?
class Automobile {
private String drive() {
return "Driving vehicle";
}
}
class Car extends Automobile {
protected String drive() {
return "Driving car";
}
}
public class ElectricCar extends Car {
@Override
public final String drive() {
return "Driving electric car";
}
public static void main(String[] wheels) {
final Car car = new ElectricCar();
System.out.print(car.drive());// output?
}
}

18D51F6598
ReplyDeletesteroid fiyat
Cam Show
steroid al
28FD8A2846
ReplyDeleteCanlı Show Whatsapp
Ücretli Show
Whatsapp Görüntülü Show Güvenilir
ReplyDeleteExploring new ways to stay connected, I recently came across an interesting link that caught my attention. If you're interested in tech updates, you might want to check out https://t.co/Ye9FIjHQ5p for some insightful information. Staying informed is essential in today's fast-paced world, and this resource offers valuable content to keep you in the loop. Remember, knowledge is power, so make sure to stay updated.
47E6F7D6
ReplyDeleteForum
Forum
Forum
Forum
Forum
Forum
Forum
Forum
Forum