Home Tutorialhelp Comment Difference Between methods and constructor

 
 

Comment

rahul
Difference Between methods and constructor,
March 17, 2008 at 12:38 AM

class another{
int x,y;
another(int a, int b){
x = a;
y = b;
}
another(){
}
int area(){
int ar = x*y;
return(ar);
}
}
public class Construct{
public static void main(String[] args)
{
another b = new another();
b.x = 2;
b.y = 3;
System.out.println("Area of rectangle : " + b.area());
System.out.println("Value of y in another class : " + b.y);
another a = new another(1,1);
System.out.println("Area of rectangle : " + a.area());
System.out.println("Value of x in another class : " + a.x);
}
}
in this given example what is the difference if we
access class named another by initializing its variable values through constructor and if we directly call area method and calculate the result?
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

What is the difference between a constructor and a method?
What is the difference between a constructor and a method?  Hi, What is the difference between a constructor and a method?   Hi, I have found a good link of Java program related to difference between constructor 

Java Beginners

Difference between Java IO Class - Java Beginners
Difference between Java IO Class  What is the difference in function between Two set of Stream class as mention below- 1)FileInputStream... of OutputStream. 2. You can construct a FileOutputStream object by passing 

Java Tips and Examples

Java - Constructor in java
Java - Constructor in java     ...) something related to the class's methods. Constructor is the method which name is same to the class. But there are many difference between the method (function 

Java Interview Questions

Constructor
the following links: http://www.roseindia.net/java/java-tips/oop/constructors/constructor.shtml http://www.roseindia.net/java/beginners/Construct.shtml...Constructor  what is the advantage of a constructor ? not the purpose 

Java Interview Questions

constructor
: a call to a constructor method. Constructor methods are special methods provided by each Java class that are responsible for initializing new objects... in Java?   Suppose there is a statement: Date today = new Date 

Java-Tutorials

Java Constructor
. A default constructor with no arguments will be called automatically by the Java.... Constructor are declared in the same way methods are declared only difference is that the constructor don't have any return type 

Java Beginners

constructor overriding - Java Beginners
constructor overriding  Write a program to demonstrate the overriding of constructor methods 

Servlet Interview Questions

Difference between ServletContext and ServletConfig
Difference between ServletContext and ServletConfig   What is the difference between ServletContext and ServletConfig?   ServletContext :Defines a set of methods that a servlet uses to communicate with its servlet 

Swing AWT

difference between applet and swings
difference between applet and swings  what are the major difference between swing and applets   Hello Friend, Differences: 1) AWT stands... the methods that are written in Java. Therefore AWT is heavy weight component 

Java Beginners

difference between the obj and reference - Java Beginners
difference between the obj and reference  what is the difference between object and reference ? is there any difference 

Java Beginners

java methods - Java Beginners
java methods  Hello, what is difference between a.length() and a.length; kindly can anybody explain. thanks for your time  Hi Friend, length() is used to find the length of string whereas length is used 

Java Beginners

Difference between object and instance? - Java Beginners
Difference between object and instance?  What is the difference between object and instance in java 

Java Beginners

Give difference between LinkedList and ArrayList - Java Beginners
Give difference between LinkedList and ArrayList  Hi, What is the use of LinkedList and ArrayList? How you can difference between LinkedList.../beginners/array_list_demo.shtml http://www.roseindia.net/java/beginners/linked 

Java Beginners

what is difference between objectan primitive? - Java Beginners
what is difference between objectan primitive?  whatis difference between object and primitive 

Java Beginners

Constructor - Java Beginners
Constructor  Do u have a constructor example program that has... in Constructor : import java.io.*; class another{ another() throws Exception...("Second Number" + num2); } } public class Construct{ public static void main 

Java Beginners

difference between java5 and java6 - Java Beginners
difference between java5 and java6  Hi, What is difference between java5 and java6 Please let me know quickly 

Java Beginners

difference between enum and final class?
difference between enum and final class?  what is the difference between enum and final class in java?   The java.lang.Enum is an abstract class, it is the common base class of all Java language enumeration types 

Java Beginners

Hi .Difference between two Dates - Java Beginners
Hi .Difference between two Dates  Hi Friend.... Thanks for ur Very good response.. Can u plz guide me the following Program.... difference between two dates.. I need to display the number of days by Each Month 

Java Beginners

Difference between API and Assembly - Java Beginners
Difference between API and Assembly  Can anybody tell me what is the diffrenece between API's and assemblies?  Hi friend, Points to be remember : API *) API Stands for "Application Program Interface 

Java Interview Questions

difference between == and === operators?
difference between == and === operators?  Is (====) operator available in java or not? difference between 

JDBC Questions

difference
difference    what is the difference between the JDBC-ODBC bridge, the Native-API-Partly-Java driver, and the JDBC-Net-All-Java Driver is the placement of the database access libraries   Please visit the following link 

Java Beginners

difference
difference  difference between Method Overloading and method Overriding   Difference between Method Overloading and Method Overriding... the following links: Java Method Overloading Java Method Overriding 

Java Beginners

difference
difference  difference between thread and process in java   Difference between Process and Thread: 1)Process is a program under execution whereas Thread is a part of program. 2)Process are heavy weight programs which 

Java Technology Tutorials

Difference between abstract class and an interface
search for overridden methods. There is no any difference between a interface...Difference between abstract class and an interface The difference between... between abstract class and interface in java. Abstract class is a class 

Java Beginners

What is the difference between a break statement and a continue statement?
What is the difference between a break statement and a continue statement?   Hi, What is the difference between a break statement and a continue...://www.roseindia.net/java/beginners/break.shtml http://www.roseindia.net/java/beginners 

Java Interview Questions

Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java 

Java Beginners

to calculate the difference between two dates in java - Java Beginners
to calculate the difference between two dates in java  to write a function which calculates the difference between 2 different dates 1.The function... difference in milliseconds long day = milis2 - milis1 

Java Beginners

difference between lock and synchronization
difference between lock and synchronization  Hi, I am new in java please anyone tell me difference between lock and synchronization in java. its urgent. Thank in advance   Please visit the following link: Lock 

Java Interview Questions

difference between hashcode,reference in java
difference between hashcode,reference in java  difference between hashcode,reference in java 

JSP Interview Questions

Difference between forward and sendRedirect
Difference between forward and sendRedirect  What's the difference between forward and sendRedirect?   RequestDispatcher.forward() and HttpServletResponse.sendRedirect() are the two methods available for URL redirecting 

Java Interview Questions

What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Read Here Thanks 

Java Beginners

what is the difference between jdk 1.4 and 1.5 and 1.6
what is the difference between jdk 1.4 and 1.5 and 1.6  what is the difference between jdk 1.4 and 1.5 and 1.6   Java 1.4 Features..., JSSE, JAAS) - Java web start Java 5.0 Features - Generics: provides compile 

Java Magazine Questions

Difference between error and exception ????????
Difference between error and exception ?  Can we handle a error in java if yes than give an code of an example? Difference between error and exception handling.......   Exceptions are things you can create/throw 

Java Technology Tutorials

Constructor Overloading in Java
Constructor Overloading in Java     ... the constructor overloading in Java. Constructors are used to assign initial values... will be called automatically by the Java Virtual Machine (JVM). Constructor is always 

Java Beginners

Constructor - Java Beginners
for more information. http://www.roseindia.net/java/beginners/Construct.shtml...Constructor  What is a constructor? What are its special properties?  Hi friend, A constructor, in object oriented programming concept 

Java-Tutorials

Difference between Encapsulation and Abstraction in Java
In this section we will discuss about the difference between Encapsulation and Abstraction in Java. Encapsulation is a process of hiding all the data.... Abstraction in Java is represented by Interface, Abstract class, Abstract methods 

Java Beginners

difference between wite and writeto in java
difference between wite and writeto in java  I am using the stream... the writeTo() method. I want to know difference between the write() and writeTo() method in java.   The writeTo() method writes the complete contents 

Servlet Interview Questions

difference between servletconfig and servletcontext in java
difference between servletconfig and servletcontext in java  difference between servletconfig and servletcontext in java   ServletContext ServletContext is implemented by the servlet container for all servlet 

Applet Questions

difference - Applet
difference  what is the difference in between awt and swing package... and what is the difference in between frame,panel  Hi Friend... as JFC?s (Java Foundation classes). 2) AWT components use native methods 

Java Beginners

constructor - Java Beginners
, A java constructor has the same name as the name of the class to which it belongs. Constructor's syntax does not include a return type, since constructors...constructor  what is constructor? give some simple example what 

Java Beginners

Constructor - Java Beginners
Constructor  why can use constructor in java .without constructor Can we run program in java..?  to create an object constructor needed..., http://www.roseindia.net/java/ Thanks 

Java Interview Questions

What is difference between the java and javascript?
What is difference between the java and javascript?  What is the difference beteen the java and javascript?   Hello Friend, Difference: 1) Java is a Object Oriented programming language developed by Sun Microsystems 

Java Interview Questions

difference between servletconfig and servletcontext in java
difference between servletconfig and servletcontext in java  ServletConfig is implemented by the servlet container to initialize a single servlet using init(). ServletContext is implemented by the servlet container for all 

Java Beginners

Difference in two dates - Java Beginners
on that. The thing is, that I need to find the difference between the two dates in JAVA..... if something happens in my application, I want to get the difference between the current... the difference between two dates. public class DateDiffDemo { public static 

Java Beginners

Difference between documentation comment and multiline comment in java?
Difference between documentation comment and multiline comment in java?  Difference between documentation comment and multiline comment in java 

Java Interview Questions

difference between marker and tag interface - Java Interview Questions
difference between marker and tag interface  what is the difference between marker interface and tag interface?  Hi friend, nterface...); } Marker Interface In java language programming, interfaces with no methods 

Java Beginners

What is the difference between a JDK and a JVM?
What is the difference between a JDK and a JVM?  Hi, What is the difference between a JDK and a JVM? Thanks,   Hi, JDK is stand... to compile your source files using a JVM. For more difference between JDK and JVM 

Java Tips and Examples

Java - The switch construct in Java
same as If-Else construct. This is the difference between Switch and If-Else... Java - The switch construct in Java       Switch is the control statement in java which 

Java Beginners

Java Methods Problem - Java Beginners
Java Methods Problem  I have to write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask... String type; private OctaviaR_A15 ()// constructor; doesn't take any arguments 

Java Beginners

Java Methods Problem - Java Beginners
Java Methods Problem  I have to write a program that has three types of pie. Apple, which is the default pie, cherry and pumpkin. I then have to ask... String type; private OctaviaR_A15 ()// constructor; doesn't take any arguments 

Servlet Interview Questions

difference between init() & init(ServletConfig config)?
difference between init() & init(ServletConfig config)?  I want to know the difference between init() and init(ServletConfig config) methods in GenericServlet 

Java Beginners

creating class and methods - Java Beginners
of the Computers. This class contains following methods, - Constructor method 

JSP Servlet Questions

RequestDispatcher object, difference between include( ) and forward( ) method.
RequestDispatcher object, difference between include( ) and forward( ) method.  The RequestDispatcher object has two methods, include( ) and forward( ). What is the difference 

Servlets-Tutorials

Difference Between Servlet and JSP
Difference Between Servlet and JSP In this section we will describe... the differences between Servlet and JSP. Servlet Servlet is a Java class that is usually... into Servlet you would have to write inside the Java code. Servlet is a compiled 

Java Interview Questions

Difference between C++ and Java - Java Interview Questions
Difference between C++ and Java  Basic difference between C... was derived from C++ but still there is big difference between these two... am going to give you few differences between these two...1. Java does not support 

Programming Tutorials

Difference between the local and class variable.
methods of any class. Whereas the local variable exits within the methods of any class. Below two program are shown which help you to understand the difference between the class and local variable. Showing Local Variable 

Framework Questions

Difference between getting a document using DOMParser & DocumentBuilderFactory !!!
. I could not understand the difference between these 2 methods.. Can anyone...Difference between getting a document using DOMParser & DocumentBuilderFactory !!!  Hi, In DOM tutorials, on one page a document is formed using 

Programming Tutorials

Constructor in java
links Constructor in Java..., a constructor for that class is called. Constructors are used to initialize the instance variables (fields) of an object. Constructors are similar to methods 

Core Java

Difference between equals() and == ?
Difference between equals() and == ? In this section you will find the difference between equals() and ==. When we create a object using new keyword.... But one more difference is that equals() is a method and "= =" 

Java Interview Questions

Java methods
Java methods  What are the differences between == and .equals 

Java Beginners

methods type - Java Beginners
methods type in Java  Give me an example programs of methods types in Java 

SQL Question

difference
difference  what's the difference between mysql and sql 

JDBC Questions

difference
difference  difference between hashtable and hashtree 

Hibernate Questions

Difference between sorted and ordered collection in hibernate
Difference between sorted and ordered collection in hibernate  What is difference between sorted and ordered collection in hibernate?   ... the sorting features provided by the Java collections framework. The sorting occurs 

Java Beginners

In Java, what's the difference between public, default, protected, and private?
In Java, what's the difference between public, default, protected, and private?  In Java, what's the difference between public, default, protected, and private 

Java Beginners

pls tell me the difference between the run() and start() in threads in java....
pls tell me the difference between the run() and start() in threads in java....  difference between the run() and start() in threads in java 

Java Beginners

what is the difference between access specifiers and access modifiers in java?
what is the difference between access specifiers and access modifiers in java?  what is the difference between access specifiers and access modifiers in java 

Java Beginners

What is the difference between an if statement and a switch statement?
What is the difference between an if statement and a switch statement?   Hi, What is the difference between an if statement and a switch statement... in Java program. http://www.roseindia.net/java/java-tips/flow/switch/switch 

Java Beginners

Difference
Difference  What Is the difference between JDK & SDK 

Programming Tutorials

Difference between == and equals method in java
Description: For comparing equality of string ,We Use equals() Method. There are two ways of comparison in java. One is "==" operator and another "equals()" method .  "==" compares the reference 

Framework Questions

What is the difference between EJB 3.0 and JPA - Framework
What is the difference between EJB 3.0 and JPA   What is the difference between EJB 3.0 and JPA. How can they work together. Does EJB 3.0 need... which can be used for creating a mapping between plain java bean objects (POJO 

Development process Questions

difference
difference  difference b/w java and asp.net 

Java-Tutorials

Difference between GenericServlet and HttpServlet
In this section we will discuss about the difference between GenericServlet...(), getServletInfo() methods and one of them must be overridden. GenericServlet does not have doGet() and doPost() methods. GenericServlet requires HttpServlet 

Struts Questions

difference between ForwardAction and IncludeAction
difference between ForwardAction and IncludeAction  What is the difference between ForwardAction and IncludeAction 

JavaScript Questions

difference between SessionState and ViewState
difference between SessionState and ViewState  What is the difference between SessionState and ViewState 

Struts Questions

Difference between DispatchAction and LookupDispatchAction
Difference between DispatchAction and LookupDispatchAction  What is the Difference between DispatchAction and LookupDispatchAction 

Java Server Faces Questions

Difference between struts and JSF
Difference between struts and JSF  What is the difference between struts and JSF 

Java Tips and Examples

Date Difference
Date Difference       This example learns how to make the difference between two dates and how... Object class and makes a difference between a Date object and a set of integer 

Java Beginners

Methods in Java - Java Beginners
Methods in Java  Hello. Currently i am involved in a group project and we have each been given a specific part of code to create our joint programI however have been given the job to create a method for storing and recalling 5 

General

Class, Object and Methods
) something related to the class's methods. Constructor is the method which name is same to the class. But there are many difference between the method (function... C:\chandan>java Construct Area of rectangle : 6 

Web Services

Difference between Web Server and Application Server
In this section we will learn the difference between Web Server... dynamically. For example, J2EE application server can run EJBs (Enterprise Java Beans... Application server provides methods that client applications can call. Application 

Java Beginners

Overloaded methods - Java Beginners
Overloaded methods  Write two overloaded methods that return the average of an array with the following headers: a) public static int average(int[] array) b) public static double average(double[] array)   Hi Friend 

Java Beginners

What is the difference between the >> and >>> operators?
What is the difference between the >> and >>> operators?   hi, What is the difference between the >> and >>> operators? Thanks 

Mobile Applications Questions

Difference between 3d and 4d
Difference between 3d and 4d  what is the difference between 3d and 4d 

SQL Question

difference between varchar & varchar2?
difference between varchar & varchar2?  What is the difference between varchar & varchar2 

Core Java

Constructor overloading in java
Constructor overloading in java In this section we will discuss about constructor overloading in java. Constructor overloading is not much different from... multiple constructor with different signature, only one difference 

Java Interview Questions

what is the difference in java and j2ee
what is the difference in java and j2ee  Hi, Please tell me: 1. What is the difference between Java and Core Java and 2. Difference between Java and J2EE 

Java Beginners

String Methods - Java Beginners
 

Java-Tutorials

Constructor Overloading in Java
In this section we have discussed about Constructor Overloading in Java... like methods, their name are same as class name. Constructor called by new operator. A default constructor however is automatically called by the Java Virtual 

Java-Tutorials

Java Constructor Overloading Example
. As we see earlier that a constructor in Java are the special type of methods...Java Constructor Overloading Example In this section we will read about the constructor overloading in Java. We will see how the constructor overloading 

Java Interview Questions

Java constructor
Java constructor  When does the compiler supply a default constructor for a class 

SQL Question

Difference between Mysql and SQL
Difference between Mysql and SQL  hello, What is the difference between Mysql and SQL??   hii, SQL is structural quary language but mysql is database package 

JSP Interview Questions

Difference between JSP and Servlets
Difference between JSP and Servlets  What is the difference between JSP and Servlets ?   JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP 

Java Beginners

Difference between SCJP Exams
Difference between SCJP Exams  What is the differences between SCJP 5 (310 - 055) exam and SCJP 6 (310 - 065) exam??? Thank You In Adv 

Java-Tutorials

Fields and Methods in Java
and methods in Java that will help beginners in Java to understand the topic...In this section we are discussing about Fields and Methods in Java. Fields or variables of class and Methods of a class are important while writing the Java 

JSP Interview Questions

Difference between request.getRequestDispatcher() and context.getRequestDispatcher()
Difference between request.getRequestDispatcher() and context.getRequestDispatcher()  What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?   request.getRequestDispatcher 

SQL Question

Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every instence of character with character sting by the given charator of string 

Java Beginners

constructor or object
constructor or object  object or construct which create first?   A constructor is always created first. Here is an example: class Example { Example(String st){ System.out.println(st); } public 

Struts-Tutorials

Difference between Struts and Spring
To know the difference between Struts and Spring, we must first explain and understand both the frameworks a little. Spring framework is a Java platform that is used to develop modular, portable and testable Java applications 

JSP Interview Questions

Difference between GET and POST
Difference between GET and POST   Difference between GET and POST ?   The difference between a GET and a POST is the way data is transferred to a servlet. With a GET, the URL will show each name/value pair on the query 

Advertisements Advertisements
 

 

 

DMCA.com