/* related posts with thumb nails */


1. What is ‘this’.

“this” refers to current object i.e. it holds the reference of current object. This can be used to differentiate super class members/local variables and its own class members.

2. What is ‘super’.

“super” is a keyword used to refer to parent class members or cntstructers.

3. What is Inheritance?

Inheritance is the process of deriving a new class from an existing class. The existing class is known as base or parent or super class. The new class is known as derived or child or sub class.

4. What are the advantages of inheritance?

· We can arrange classes in hierarchy model.

· It offers reusability of the code.

· It allows modifications without affecting the existing class.

· Programmer need not write everything from scratch when preparing new classes to extend the features of existing classes.

5. How do you use the keyword ‘extends’?

‘extends’ is a keyword used to take inheritance from a class. The syntax to take inheritance is shown below.

class base_class { ……. }

class derived_class extends base_class { ……. }

6. What are the forms(types) of Inheritance?

Inheritance can be formed mainly in four ways:

§ Single inheritance

§ Multilevel inheritance

§ Multiple inheritance

§ Hierarchical inheritance

§ Hybrid Inheritance

7. What is Single inheritance:

If a class is derived from another class, it can be called as single inheritance.

Syntax: class A { ……. }

class B extends A { ……. }

8. What is Multilevel inheritance?

If a class is derived from the class, which is derived from another class, it can be called as multilevel inheritance.

Syntax: class A { ……. }

class B extends A { ……. }

class C extends B { ……. }

9. What is Multiple inheritance?

If a class is derived from two or more classes, it can be called as multiple inheritance. Java does not support this type of inheritance.

10. What is Hierarchical inheritance?

If two or more classes are derived from a class, it can be called as hierarchical inheritance.

Syntax: class A { ……. }

class B extends A { ……. }

class C extends A { ……. }

11. What is Hybrid inheritance?

This could be the combination of multiple and multilevel inheritance. Java does not support this type of inheritance.

12. What are final variables?

Final variables cannot be altered at later stages in the program once it has been initialized. These are similar to constant variables in C and C++ declared with the keyword ‘const’.

13. What are final methods?

The methods that cannot be overridden in child classes are known as final methods.

14. What are final classes?

A class that cannot be inherited is called Final class. In simple terms, a final class is the one which cannot have any subclasses.

15. What is method overloading?

Having any number of functions with the same name provided they take different number of arguments or different types of arguments, is method overloading.

16. What is method overriding?

Method overriding is writing a member function in a derived class with the same name and signature of an existing member function of the base class. In such cases, the member function of the derived class is called with the objects of the derived class.

17. What are the differences between method overloading and method overriding?

Method Overloading

Method Overriding

It allows you to have any number of functions with the same name provided they take different number of arguments or different types of arguments.

If a function with same signature is present both in parent and child classes, with the instances of child classes; child class methods are called.

Function signature is different

Function signature is same

Scope of the overloading methods can be in a same class or one in sub class and the other in child class.

Scope of the overriding methods is different i.e. one is present in parent class and the other is present in child class.

Here, we expect same behavior but on different operands.

Here, we expect different behavior (modified version) but with the same method name. This is also known as redefinition.

18. What is finalize () method?

This is similar to destructors in C++, The finalizer method is simply finalize() and can be added to any class used to release system resources such as open files or open sockets before getting collected. Before an object is garbage collected, the runtime system calls its finalize() method.

19. What is the purpose of finalize () method?

finalize() is best used for the following transactions.

· Memory deallocations

· To free non-object resources

· To close file streams

· To close database connections

· To close network sockets.

20. What are Varargs?

Varargs represents variable length arguments in methods.

21. What are access specifiers? Or What is visibility control?

Access modifiers (visibility control) determine the accessibility of the members of a class. Java provides three types of visibility modifiers: public, private and protected.

22. What is public access?

A variable or method declared as public has the widest possible visibility and accessible everywhere.

23. What is friendly (default) access?

When no access modifier is specified, the member defaults to a limited version of public accessibility known as "friendly" This makes fields visible only in the same package, but not in other packages.

24. What is protected access?

The visibility level of a "protected" field lies in between the public access and friendly access. That is, the protected modifier makes the fields visible not only to all classes and subclasses in the same package but also to subclasses in other packages

25. What is private access?

private fields have the highest degree of protection. They are accessible only with their own class. They cannot be inherited by subclasses and therefore not accessible in subclasses.

26. What is private protected access?

This modifier makes the fields visible in all subclasses regardless of what package they are in. Remember, these fields are not accessible by other classes in the same package.

27. Tabulate the visibility provided by various access modifiers.

Access modifier à




private protected


Own class






Sub class

in same package






Other classes

In same package






Sub class

in other package






Other classes

In other package






28. What is an abstract method?

Abstract method is a method which does not have any body (implementation). It is defined with the keyword “abstract”. .

29. What are Abstract classes?

Abstract classes are the classes which can be subclassed but not instantiated. An abstract class may have both abstract methods and normal methods.

Related Topics:


Post a Comment