Shih-Min Lee's Personal website

dating, chating, food, games, search

Follow me on GitHub

Java related questions

What is a class?

A class is simply a representation of a type of object with pre-defined properties and behaviors.

Define a constructor?

Constructor is a method used to initialize the state of an object upon the creation of the object itself.

Define Destructor?

Destructor is a method which is called when the object is destroyed.

What is OOPS

in which programs are considered as a collection of objects.

What is a virtual function?

Virtual function is a member function of class and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.

Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.

What is function overloading?

Function overloading is defined as a normal function, but it has the ability to perform different tasks.

What is an abstract class?

An abstract class is a class which cannot be instantiated. Creation of an object is not possible with abstract class , but it can be inherited. An abstract class can contain only Abstract method. Java allows only abstract method in abstract class while for other language it allows non-abstract method as well.

An example is this

public abstract Animal
{
   public void eat(Food food)
   {
        // do something with food....
   }

   public void sleep(int hours)
   {
        try
    {
        // 1000 milliseconds * 60 seconds * 60 minutes * hours
        Thread.sleep ( 1000 * 60 * 60 * hours);
    }
    catch (InterruptedException ie) { /* ignore */ }
   }

   public abstract void makeNoise();
}

What is super keyword?

Super keyword is used to invoke overridden method which overrides one of its superclass methods. This keyword allows to access overridden methods and also to access hidden members of the superclass.

It also forwards a call from a constructor to a constructor in the superclass.

What is an interface?

An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.

What are base class, sub class and super class?

Base class is the most generalized class , and it is said to be a root class.

Sub class is a class that inherits from one or more base classes.

Super class is the parent class from which another class inherits.

What is method overriding?

Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will overrides the implementation in the superclass by providing the same method name, same parameter and same return type.

What is ‘this’ pointer?

THIS pointer refers to the current object of a class.

What is a Java superclass

A Java superclass is a class which gives a method or methods to a Java subclass.

What is Class Abstraction.

Abstraction is a good feature of OOPS , and it shows only the necessary details to the client of an object.

What is Class Encapsulation.

Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.

What is Class Inheritance.

Inheritance is a concept where one class shares the structure and behavior defined in another class. Ifinheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

What is Class Polymorphism

Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Simply, polymorphism takes more than one form.

What are the various types of constructors?

There are three various types of constructors , and they are as follows:.

– Default Constructor – With no parameters.

– Parametric Constructor – With Parameters. Create a new instance of a class and also passing arguments simultaneously.

– Copy Constructor – Which creates a new object as a copy of an existing object.

What is early and late binding?

Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.