Interface:
Interface is a reference type in Java, which contains a collection of abstract methods.
An interface needs to the follow certain conditions such as:
- One cannot instantiate an interface.
- Interfaces do not contain any constructors.
- All methods present in the interface are abstracts.
- An interface does not contain any instance field.
- An interface cannot be extended by a class.
Comparable Interface:
A comparable interface is a generic interface that defines the compareTo() method that is used for comparing objects.
Using comparable interface, one can choose the properties of the objects, rather than the reference location of the objects.
Example:
//java langauage package for comaprable interface
package java.lang
//comparable interface definition
public interface Comparable <E>
{
//use of compareTo to compare objects
public integer compareTo(E o);
}
The compareTo() method determines the order of this object with the specified object “o” and returns a negative integer, zero or positive integer, if this object is less than, equal to or greater than object “o”.
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- Arrays are passed to methods by value; not by reference. True Falsearrow_forwardIn python and include doctring: First, write a class named Movie that has four data members: title, genre, director, and year. It should have: an init method that takes as arguments the title, genre, director, and year (in that order) and assigns them to the data members. The year is an integer and the others are strings. get methods for each of the data members (get_title, get_genre, get_director, and get_year). Next write a class named StreamingService that has two data members: name and catalog. the catalog is a dictionary of Movies, with the titles as the keys and the Movie objects as the corresponding values (you can assume there aren't any Movies with the same title). The StreamingService class should have: an init method that takes the name as an argument, and assigns it to the name data member. The catalog data member should be initialized to an empty dictionary. get methods for each of the data members (get_name and get_catalog). a method named add_movie that takes a Movie…arrow_forwardPlease help me this I need answer typing clear urjent no chatgpt used i will give 5 upvotesarrow_forward
- Method Overloading is a feature that allows a class to have two or more methods having same name, if their argument lists are different. Argument lists could differ in: 1. Number of parameters. 2. Data type of parameters. 3. Sequence of Data type of parameters. Write different version of method sum() that display the sum of the values received as parameter according to the following main method content: public static void main(String[] args) { sum ( 10, 10 ); sum ( 10, 10, 10 ); sum ( 10.0, 10.0 ); sum ( 10, 10.0 ); sum ( 10.0, 10); } You have to define five functions with the specified types. Then, demonstrate the Argument Promotion concept by reducing the number of method to two.arrow_forwardList the name and return type of this method: public String getCode(){ return code;}arrow_forwardA GradeBook Example : In this example ,GradeBook class has one attributeand some methods to access this attribute data:public class GradeBook { private String cname; public void setName(String name){ cname=name;}public String getName(){return cname;} public void showMessage(){System.out.printf("Welcome to the Grade Book of %s \n", getName());}} //End of ClassTest Class Example that uses GradeBook class:public class GradeBookTest {public static void main(String[] args) { GradeBook b1=new GradeBook();GradeBook b2=new GradeBook(); System.out.printf("Course Name %s \n",b1.getName());System.out.printf("Course Name %s \n",b2.getName()); b1.setName("Object Oriented Programming");b2.setName("Data Structure using Java"); System.out.printf("Course Name %s \n",b1.getName());System.out.printf("Course Name %s \n",b2.getName()); b1.showMessage();b2.showMessage();}}//End class Exercise:You need to include another two attribute with name“marks” and “totalstudents” in GradeBook Class, Usefunctions to…arrow_forward
- For the following class: 1. write a toString method to return a String that represents the information stored in a Person object including name, lastName, and age. //2 points 2. write an equals(Object obj) to return false if the passed object is null or not a Person. The method equal returns false, if one of name, lastName, and age of the object which it is applied to is not equal to name, lastName, and age of the object that is passed as argument. Otherwise, the method returns true. //3 points public class Person { private String name; private String lastName; private int age; public Person (String name, String lastName, int age) { this.name = name; this.lastName = lastName; this.age age; }arrow_forwardJAVAA7-Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned.arrow_forwardWrite an equals method for the Car class given here. Two Cars are equal if their Vehicle Identification Numbers (VIN) are the same. HINT: The String class has an equals method that can be called from the Car class equals method.arrow_forward
- Computer programmin Javaarrow_forwardUse this code template to continue the code: public Item(String name, double weight, int value) Initializes the Item’s =ields to the values that are passed in; the included =ield is initialized to false public Item(Item other) Initializes this item’s fields to the be the same as the other item’s public double getWeight() public int getValue() public boolean isIncluded() Getter for the item’s fields (you don’t need a getter for the name) Given code: public class Item { private final String name; private final double weight; private final int value; private boolean included; public Item(String name, double weight, int value) { this.name = name; this.weight = weight; this.value = value; } public Item(Item item){ name = item.name; weight = item.weight; value = item.value; } public void…arrow_forwardprivate float c; private void method2(double y) { c = y; } in another class we created an object of the first class then within in it : tester.method2 (10.0f); are there any errors ? how many errors if there are any and with explanation please.arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT