What do u mean by method and also contructer in java ?

Answer Posted / hira ratan sharma

Java methods are similar to functions or procedures in other
programming languages.

Every Java program must have one main() method.

Here is the main() method from a Java program which prints
"Hello World":

public static void main (String[] args) {
// This Java program prints "Hello World!"
System.out.println{"Hello World!");


A constructor creates an Object of the class that it is in
by initializing all the instance variables and creating a
place in memory to hold the Object. It is always used with
the keyword new and then the Class name. For instance, new
String(); constructs a new String object.

COnstructors are basically used to initialize the attributes
of the class.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the implementation of destroy method in java. Is it native or java code?

480


What are the three parts of a lambda expression?

532


Is java util list serializable?

533


Which collection is ordered in java?

531


Can a singleton class be inherited?

523






What is the default value of local and global variables?

559


Can we able to pass objects as an arguments in java?

530


What is the difference between arraylist and hashset in java?

514


What is the char data type?

519


What is double in java?

511


What is abstract class? Explain

593


What is immutable data?

576


What is role of void keyword in declaring functions?

570


What are the types of inner classes (non-static nested class) used in java?

561


What is the difference between throw and throws in java?

548