Posts

A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class - Hacker Rank Solution.

A Java abstract class is a class that can't be instantiated. That means you cannot create new instances of an abstract class. It works as a base for subclasses. You should learn about Java Inheritance before attempting this challenge. Following is an example of abstract class: abstract class Book { String title ; abstract void setTitle ( String s ); String getTitle (){ return title ; } } If you try to create an instance of this class like the following line you will get an error: Book new_novel = new Book (); You have to create another class that extends the abstract class. Then you can create an instance of the new class. Notice that  setTitle  method is abstract too and has no body. That means you must implement the body of that method in the child class. In the editor, we have provided the abstract  Book  class and a  Main  class. In the Main class, we created an instance of a class called  MyBook . Your ta...

Using inheritance, one class can acquire the properties of others.

  Using   inheritance , one class can acquire the properties of others. Consider the following   Animal   class: class Animal { void walk (){ System . out . println ( "I am walking" ); } } This class has only one method,  walk . Next, we want to create a  Bird  class that also has a  fly  method. We do this using  extends  keyword: class Bird extends Animal { void fly () { System . out . println ( "I am flying" ); } } Finally, we can create a Bird object that can both  fly  and  walk . public class Solution { public static void main ( String [] args ){ Bird bird = new Bird (); bird . walk (); bird . fly (); } } The above code will print: I am walking I am flying This means that a Bird object has all the properties that an Animal object has, as well as some additional unique properties. The code above is provided for you in your...

You are given a date. You just need to write the method getDay which returns the day on that date - Hacker Rank Solution.

Image
The  Calendar class   is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. You are given a date. You just need to write the method,  , which returns the  day  on that date. To simplify your task, we have provided a portion of the code in the editor. Function Description Complete the  findDay  function in the editor below. findDay  has the following parameters: int:  month int:  day int:  year Returns string:  the day of the week in capital letters Input Format A single line of input containing the space separated month, day and year, respectively, in   MM DD YYYY    format. Sample Input 08 05 2015 Sample Output WEDNESDAY Explanation The day on August 5 th  2015 was  WEDNESDAY . SOLUTION :...