Wednesday, December 5, 2018

java Interview Question

Commonly Asked Java Programming Interview Questions 

What is “this” keyword in java?
Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.
Usage of this keyword
  • Used to refer current class instance variable.
  • To invoke current class constructor.
  • It can be passed as an argument in the method call.
  • It can be passed as argument in the constructor call.
  • Used to return the current class instance.
  • Used to invoke current class method (implicitly)

What is an abstract class? How abstract classes are similar or different in Java from C++?
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.

        Like C++, in Java, an instance of an abstract class cannot be created, we can have references of abstract class type though.
  • Like C++, an abstract class can contain constructors in Java. And a constructor of abstract class is called when an instance of a inherited class is created
  • In Java, we can have an abstract class without any abstract method. This allows us to create classes that cannot be instantiated, but can only be inherited.

No comments:

Post a Comment

Which Python course is best for beginners?

Level Up Your Python Prowess: Newbie Ninjas: Don't fret, little grasshoppers! Courses like "Learn Python 3" on Codecade...