Question
public class Shape
{
public int area()
{
return 1;
}
}
public class Square extends Shape
{
public int area()
{
return 2;
}
}
public class Rectangle extends Shape
{
public int area()
{
return 3;
}
}
class Main()
{
public static void main(String[] args)
{
Shape shape = new Shape();
Square square = new Square();
Rectangle rect = new Rectangle();
rect = (Rectangle)shape;
System.out.println(square.area());
}
}
a.
Compilation failure
b.
3
c.
Runtime Exception
d.
2
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 outcome of below code Main class?
Similar Questions
Discover Related MCQs
Q. Which feature of java 8 enables us to create a work stealing thread pool using all available processors at its target?
View solution
Q. What does Files.lines(Path path) do?
View solution
Q. What is Optional object used for?
View solution
Q. What is the substitute of Rhino javascript engine in Java 8?
View solution
Q. What does SAM stand for in the context of Functional Interface?
View solution
Q. Which of these Exception handlers cannot be type parameterized?
View solution
Q. Which of the following cannot be Type parameterized?
View solution
Q. Which statement is true about assertions in the Java programming language?
View solution
Q. Which three statements are true?
1. Assertion checking is typically enabled when a program is deployed.
2. It is never appropriate to write code to handle failure of an assert statement.
3. Assertion checking is typically enabled during program development and testing.
4. Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
5. Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
View solution
Q. Which statement is true?
View solution
Q. Which of the following statements is true?
View solution
Q. Which of the following statements is true?
View solution
Q. ____________method can be given parameters via using command line arguments.
View solution
Q. Number of arguments can be passed to main() is?
View solution
Q. args in an array of String.
View solution
Q. ___________ is a very small Java framework that makes it trivial to parse command line parameters.
View solution
Q. Which tab is used to pass command line argument in eclipse?
View solution
Q. Recursion in Java is a way of calling the method from within the same method. State TRUE or FALSE.
View solution
Q. Java uses ___ type of memory to implement Recursion.
View solution
Q. Java uses Stack type memory instead of Heap type memory in implementing Recursion because of ___ feature of STACK.
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!