Constructors in Java II Core Java II Selenium Automation
Автор: Knowledge Share
Загружено: 2020-12-28
Просмотров: 317
Описание:
In this session you will learn about constructors and its importance in automation
Learn this concept very carefully, because we will be using this frequently when we are designing framework
======================================
Constructor
==========================
A constructor in Java is a special method that is used to initialize objects.
The constructor is called when an object of a class is created.
It is mostly used to set initial values for object
Default Constructor
Parametarized Constructor
Classname objectname=new Constructor();
Rules :
Constructor Name should be equal to Class name
Constructor doesn't have return type
Working of a Constructor is similar to Method
************************************************************
Example program
************************************************************
package Constructor_demo;
public class Employee {
String empname;
int empid;
Employee() // Default Constructor
{
empname="John";
empid=101;
}
Employee(String name, int id) // Parameterized Constructor
{
empname=name;
empid=id;
}
public static void main(String[] args)
{
Employee obj=new Employee(); // Object Creation // Calling a Default Constructor
System.out.println("Employee Name : " + obj.empname);
System.out.println("Employee ID : " + obj.empid);
Employee obj2=new Employee("Paul",102);
System.out.println("Employee Name : " + obj2.empname);
System.out.println("Employee ID : " + obj2.empid);
}
}
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: