Question
class Sweet
{
void price()
{
System.out.print("Sweet=$10 ");
}
}
class Sugar extends Sweet
{
void price()
{
super.price();
System.out.print("Sugar=$20");
}
}
public class JavaInheritance1
{
public static void main(String[] args)
{
Sugar su = new Sugar();
su.price();
}
}
a.
Sweet=$10 Sugar=$20
b.
Sweet=$10 Sugar=$10
c.
Sweet=$20 Sugar=$20
d.
Compiler error
Posted under Java Programming
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. What is the output of the below Java program with inheritance?
Similar Questions
Discover Related MCQs
Q. Which is the keyword used to implement inheritance in Java?
View solution
Q. You can not inherit a Superclass'es constructor even after using inheritance in Java. State TRUE or FALSE.
View solution
Q. A Subclass can become a Superclass to another class extending from it in Java. State TRUE or FALSE.
View solution
Q. When a Class inherits two superclasses (not in Java), it is called ____ inheritance.
View solution
Q. In a Multi-Level Inheritance in Java, the last subclass inheritsmethods and properties of ____.
View solution
Q. In a Multi Level Inheritance Class-C inherits from Class-B and Class-B inherits from Class-A. State TRUE or FALSE.
View solution
Q. In a Single inheritance, Class Binherits only from Class A. State TRUE or FALSE.
View solution
Q. What are the types of Inheritances(Whether Java supports or not) available in Object-Oriented Programming Languages?
View solution
Q. You should use Inheritance when there is an IS-A relationship between classes. State TRUE or FALSE.
View solution
Q. Java language supports ___ type of inheritance.
View solution
Q. The class that inherits an already defined class is called ___.
View solution
Q. The class that is being inherited or subclassed is called ___.
View solution
Q. What are the features reused using Inheritance in Java?
View solution
Q. What are the features of an Object Oriented Programming (OOPs)?
View solution
Q. Which of these is supported by method overriding in Java?
View solution
Q. Which of these is correct way of calling a constructor having no parameters, of superclass A by subclass B?
View solution
Q. Which of these keywords can be used to prevent Method overriding?
View solution
Q. What is the process of defining a method in a subclass having same name & type signature as a method in its superclass?
View solution
Q. Which of this keyword can be used in a subclass to call the constructor of superclass?
View solution
Q. Does Java support multiple level inheritance?
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!