What will be the output of the following Java code snippet?public class Shape {public int area(){return 1;}}public class Square extends Shape {public int area(){return 2;}}class Main() { public static void main(String[] args) {Shape shape = new Shape();Square square = new Square();shape = square;System.out.println(shape.area());}}

🎲 Try a Random Question  |  Total Questions in Quiz: 30  |  🧠 Study this quiz with Flashcards
This question is part of a full practice quiz:
Java Basics Practice Test: Java 8 Features, Hibernate, & Liskovs Principle — practice the complete quiz, review flashcards, or try a random question.

Java 8 is a major release of the Java programming language that was released in March 2014.  Hibernate is an object-relational mapping (ORM) library that allows you to map Java objects to relational database tables. It is one of the most popular ORM libraries for Java, and it is used in a wide variety of applications. The Liskov Substitution Principle (LSP) is a principle of object-oriented programming that states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of the program. Relationship between Java 8 features, Hibernate,... Show more

What will be the output of the following Java code snippet?<br>public class Shape <br>{<br>public int area()<br>{<br>return 1;<br>}<br>}<br>public class Square extends Shape <br>{<br>public int area()<br>{<br>return 2;<br>}<br>}<br>class Main() <br>{<br> public static void main(String[] args)<br> {<br>Shape shape = new Shape();<br>Square square = new Square();<br>shape = square;<br>System.out.println(shape.area());<br>}<br>}