Skip to main content

Posts

Showing posts with the label Abstract Class

Java Abstract Class HackerRank Solution | Programming Blog

  What is Abstract Class in Java? 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. So if any other class extends abstract class then it must provide implementation of abstract method of that class otherwise you can also make child class as abstract.  Learn more about Abstract class : Abstract class in Java   See problem Description in HackeRank : Java Abstract Class Problem   Solution Explanation : In code editor, we already have Book class and Main method. We have to simply create new class MyBook that extends Book class.  As setTitle method is abstract in Book class, we must have to implement in our MyBook class if we extends Book class. So create method setTitle in MyBook class and set the title variable. And our solution is done. import java.util.*; abstract class Book{     String title;     abstract void setTitle(St...

Abstract Class and Interface Interview Questions And Answers - Programming Blog

abstract class and Interface interview questions and answers in java Lets see most asked interview questions and answers about interface and abstract class in java.  1. What is Interface in Java? Ans :- Interface is completely Abstract Class. From java 8, we can use default method in interface. Interface is just declarations of methods. Interface does not provide implementation of methods. We can implement interface and whoever class implements that interface it must provide implementation of that interface. Any class implements as many interface they want. Interface also can extends another interface. but one interface can not implements another interface. Learn more about Interface with Examples :- Interface In Java 2. What is Abstract class in Java? Ans :-  Any class defined with abstract keyword is called abstract class. Abstract class contains abstract method as well as non abstract methods also. Abstract class can not instantiated means we can not create object of abstr...