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

Answer Posted / prachi

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 ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are accessor methods in java?

753


Can java arraylist hold different types?

725


What kind of variables can a class consist?

795


Explain jvm, jre, and jdk?

783


What is the use of optional ?

788


How do you avoid global variables?

775


What is meant by distributed application? Why are we using that in our application?

754


What is dot operator?

787


What is a JAR file?

790


What class allows you to read objects directly from a stream?

1111


Explain about abstract classes in java?

802


What is string immutability?

741


Explain an algorithm to find depth of a binary tree.

791


What is the purpose of using bufferedinputstream and bufferedoutputstream classes?

802


Can we override constructor in java?

804