100 Core Java Interview Questions and Answers - Part 5

Here are top selected core java interview questions asked in high level interviews, these questions may be helpful for both freshers or experienced professional going for interview.

41) Can a class extend more than one class in Java?

No, java does not support multiple inheritance. In java a class cannot extends more than one class but it can implement as many interfaces as it wants.

42) Can we declare a class inside an interface and vice verse?

Yes, we can declare an interface inside a class and a class can be declared inside an interface, both statements are true.

43) What do you mean by a marker interface In Java?

An marker interface is an interface which does not contain any variable or method in it, these interfaces are implemented by some classes to provide special instructions to JVM. The example is serializable interface this interface does not contain anything in it, it tell the JVM that the class which implements this interface needs to be serialized.

44) What modifiers are allowed inside an interface in Java?

In java, interfaces can have public and abstract types of variables and methods in them. All the variables and methods are public abstract by default in an interface.

45) What is a constructor in java? Can constructors be overridden?

Constructors are special type of methods that have the same name as the class itself and do not have a return type not even void. Constructors are used to create an object of a class, if we do not declare any constructor in our class than JVM provides a non argument constructor by default. Constructors cannot be overridden, though a subclass can call the constructor of its super class.

46) What access specifies are available in Java?

In java there are four access specifies listed below their scope and usability.
1) public : public classes, methods and variables can be accessed from anywhere in the application, No restriction at all.
2) private: private variables and methods can be accessed in the same class only in which they are declared and not outside that, private variables and methods can not be accessed even in the subclasses.
3) protected: protected variables and methods can be accessed from anywhere in the same package and in the subclasses of same class outside the package.
4) default(no specifies): If a variable or method does not have any specifier than these can be accessed from anywhere within the same package and not outside the package.

47) What are static blocks in Java?

Static blocks are executed exactly once even before the main method is executed, these blocks are executed by jvm at the time of classes loaded in memory.

48) What is an Iterator in Java?

The Iterator is an interface which is used to step through a collection in java, Iterator has its own implementation for difrenet type of collections. Iterator has three methods next(), hashNext() and remove().

About The Author

Nagesh Chauhan

Nagesh Chauhan has 8+ years of software design and development experience in variety of technologies like - Core Java, Java 8 (Streams, Lambda), J2EE (Servlet, JSP), Spring Framework (MVC, IOC, JDBC, SECURITY etc), Spring Boot and Microservices, Kafla, Redis, Cassandra and Spark.