Sie sind auf Seite 1von 1

In class-based programming, objects are created from classes by subroutines called

constructors, and destroyed by destructors. An object is an instance of a class,


and may be called a class instance or class object; instantiation is then also
known as construction.Class is Data Type,You use this type to create object.
Instance is Logical but object is Physical means occupies some memory.Declaring
Objects (Also called instantiating a class)==When an object of a class is created,
the class is said to be instantiated. All the instances share the attributes and
the behavior of the class. But the values of those attributes, i.e. the state are
unique for each object. A single class may have any number of instances.

To call a static method displayRuns() of the class named Cricket we write


Cricket.displayRuns();
Class name is used to invoke the static method as static member does not depend on
any instance of the class.
The purpose of constructor is to initialize the object of a class while the purpose
of a method is to perform a task by executing java code.Constructor is a block of
code that initializes the newly created object.the constructor name matches with
the class name and it doesn�t have a return type.

To inherit a class we use extends keyword. Here class XYZ is child class and class
ABC is parent class. The class XYZ is inheriting the properties and methods of ABC
class.
class XYZ extends ABC
{
}
The derived class inherits all the members and methods that are declared as public
or protected. If the members or methods of super class are declared as private then
the derived class cannot use them directly. The private members can be accessed
only in its own class. The child class is able to access the private members of
parent class through protected methods of parent class. When we make a instance
variable(data member) or method protected, this means that they are accessible only
in the class itself and in child class.

a reference to an object is d address of d memory location where the object is


stored in d heap.In Java,no variable can ever hold an object.A Variable can only
hold a reference to an object.

Consider this method that we have already been using from Breezy;
int number = Console.readInt("Enter a number"); //returns a value
The method name is "readInt" which is defined in the class "Console". Since the
method is defined in the class Console, the word Console becomes the calling
object. This particular method returns an integer value which is assigned to an
integer variable named number.
You invoke (call) a method by writing down the calling object followed by a dot,
then the name of the method, and finally a set of parentheses that may (or may not)
have information for the method.
In Java, every method must be part of some class which is different from languages
like C, C++, and Python.The method needs to be called for using its functionality.

A package in Java is used to group related classes.The library is divided into


packages and classes. Meaning you can either import a single class (along with its
methods and attributes), or a whole package that contain all the classes that
belong to the specified package.To use a class or a package from the library, you
need to use the import keyword.

Das könnte Ihnen auch gefallen