In computer programming, an array is a collection of similar types of data. For example, if we want to store the names of 100 people then we can create an array of the string type that can store 100 names. String[] array = new String[ 100 ]; The number of values in the Java array is fixed. That is, the above array can not store more than 100 elements. How to declare an array in Java? In Java, here is how we can declare an array. dataType[] arrayName; dataType - it can be primitive data types like int , char , double , byte , etc. or Java objects arrayName - it is an identifier For example, double [] data; Here, data is an array that can hold values of type double . But, how many elements can array this hold? Good question! To define the number of elements that an array can hold, we have to allocate memory for the array in Java. For example, // declare an array double [] data; // allocate memory data = new ...
OR--------> ONLY ONE STATEMENT NEEDS TO BE TRUE package com.cnc ; public class Main { public static void main ( String [] args) { if (( topScore > 90 ) || ( secondTopScore )<= 90 ){ System . out .println( "Either or both of the condition are true" ); } } }
Inheritance is one of the key features of OOP (Object-oriented Programming) that allows us to define a new class from an existing class. For example, class Animal { // eat() method // sleep() method } class Dog extends Animal { // bark() method } In Java, we use the extends keyword to inherit from a class. Here, we have inherited the Dog class from the Animal class. The Animal is the superclass (parent class or base class), and the Dog is a subclass (child class or derived class). The subclass inherits the fields and methods of the superclass. is-a relationship Inheritance is an is-a relationship. We use inheritance only if an is-a relationship is present between the two classes. Here are some examples: A car is a vehicle. Orange is a fruit. A surgeon is a doctor. A dog is an animal. Example 1: Java Inheritance class Animal { public void eat () { System.out.println( "I...