Showing posts with label constructor. Show all posts
Showing posts with label constructor. Show all posts

Wednesday, 8 June 2016

Javascript Array

JavaScript array is an object that represents a collection of similar type of elements.
There are 3 ways to construct array in JavaScript
  1. By array literal
  2. By creating instance of Array directly (using new keyword)
  3. By using an Array constructor (using new key

1) JavaScript array literal

Below syntax is creating an array.
var arrayname=[value1,value2.....valueN];
Eg: var cars = ["Hyundai", "Volvo", "BMW"];

2) JavaScript Array directly (new keyword)

The syntax of javascript array using new keyword is as below.
var arrayname=new Array();  
Eg: var cars = new Array("Hyundai", "Volvo", "BMW");

3) By using array constructor

Here, you need to create instance of array by passing arguments in constructor .

Syntax:
var arrayname=new Array("param1","param2","param3")
Eg:
var emp=new Array("Hyundai","Volvo","BMW")



Sunday, 26 January 2014

READING CONSOLE INPUT

READ INPUT FROM  CONSOLE-JAVA

How to Read Input From Console in java

Reading console input in simple java console applications is a very straight forward process. Java provides developers two predefined streams in the java.lang.System class to read and write data to and from standard input and output devices. System.out is a standard output stream which is Console by default and System.in is predefined input stream which is Keyboard by default. To read user input in a console window we connect system.in with other stream classes available in java.io package.

Tuesday, 21 January 2014

Using super in java

how to use super keywords:constructors

super:

super has two general forms. The first calls the superclass’ constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass.

Monday, 20 January 2014

this KEYWORD IN JAVA

this  is a keyword in Java. Which can be used inside method or constructor of  class. It(this) works as a reference to current object whose method or constructor is being invoked. this keyword can be used to refer any member of current object from within an instance method or a constructor.

CONSTRUCTORS IN JAVA


A constructor initializes an object immediateily upon creation.It has the same name as the class in which it resides and is syntactically similar to a method.Once defined, the constructor is automatically called immediately after the object is created,before the new operator completes.Constructors look a little strange because they have no return type ,not even void.Attributes of an object may be available when creating objects if no attribute is available then default constructor is called, also some of the attributes may be known initially.