Found 9326 Articles for Object Oriented Programming

Is constructor inherited in Java?

radhakrishna
Updated on 30-Jul-2019 22:30:20

276 Views

No, constructors are not inherited in Java.

Does constructor return any value in Java?

mkotla
Updated on 30-Jul-2019 22:30:20

4K+ Views

No, constructor does not return any value. While declaring a constructor you will not have anything like return type. In general, Constructor is implicitly called at the time of instantiation. And it is not a method, its sole purpose is to initialize the instance variables. Example Live Demo public class Sample{ public Sample(){ System.out.println("This is a constructor"); } public static void main(String args[]){ Sample obj = new Sample(); } } Output This is a constructor

Can you use both this() and super() in a constructor in Java?

Samual Sam
Updated on 30-Jul-2019 22:30:20

1K+ Views

No, you cannot have both this() and super() in a single constructor.

What is constructor chaining in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

280 Views

Constructors are similar to methods but, They do not have any return type. The name of the constructor is same as the name of the class. Every class has a constructor. If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class. Each time a new object is created, at least one constructor will be invoked. A class can have more than one constructor. this() and super() are used to call constructors explicitly. Where, using this() you can call the current class’s constructor and using super() you can ... Read More

What is default, defender or extension method of Java 8?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:20

93 Views

Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8. For example, ‘List’ or ‘Collection’ interfaces do not have ‘foreach’ method declaration. Thus, adding such method will simply break the collection framework implementations. Java 8 introduces default method so that List/Collection interface can have a default implementation of foreach method, and the class implementing these interfaces need not implement the same. Syntax public interface vehicle { default void print() { ... Read More

What is the difference between Component class and Container class in Java?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:20

4K+ Views

The class Component is the abstract base class for the non-menu user-interface controls of AWT. A component represents an object with graphical representation. The class Container is the superclass for the containers of AWT. The container object can contain other AWT components.

What are Java methods equivalent to C# virtual functions?

Sharon Christine
Updated on 30-Jul-2019 22:30:22

310 Views

All instance methods in Java are virtual except, static methods and private methods.

What is a Locale class in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

121 Views

The java.util.Locale class object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to form information for the user. The locale is a mechanism for identifying objects, not a container for the objects themselves.

What is the purpose of System class in Java?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:20

1K+ Views

System class belongs to the package java.lang. It cannot be instantiated. A System class provides − standard output. error output streams. standard input and access to externally defined properties and environment variables. A utility method for quickly copying a portion of an array. a means of loading files and libraries. Following are the fields for java.lang.System class − static PrintStream err − This is the "standard" error output stream. static InputStream in − This is the "standard" input stream. static PrintStream out − This is the "standard" output stream.

What is Callable interface in Java?

Sharon Christine
Updated on 30-Jul-2019 22:30:20

576 Views

The Callable interface is found in the package java.util.concurrent. The Callable object can return the computed result done by a thread in contrast to a runnable interface which can only run the thread. The Callable object returns a Future object which provides methods to monitor the progress of a task being executed by a thread. The future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.

Advertisements