oops

 /// What is OOP's

/// Class
/// Object
/// Constructor : Default, Parameterized, Named

// main() {
// var obj = new class1(); //Creating the class Object to Access the class properties
// var obj = class1(); //Another way to creating the class object
// obj.fun1(); //Accessing the class Function through Object
// print(obj.name); //Accessing the class variable through Object
// }
// class class1 {
// var name = "Vishal"; //Creating the class Variable
// fun1() { //Creating the class Function
// print("Hello");
// }
// }

/// Use the variable in the function and Assign value to that variable through class Object
// main() {
// var obj1 = new class2();
// obj1.name = "Vishal";
// obj1.fun2();
//
// var obj2 = new class2();
// obj2.name = "Amit";
// obj2.fun2();
// }
// class class2 {
// var name;
// fun2() {
// print("Hello " + name);
// }
// }

/// Constructor
/// Default Constructor
// Constructor is a special method of Dart class which is automatically called
// when the object is created. The constructor is like a function with/without parameter
// but it doesn’t have a return type. Default, parameterized, and named constructors
// are known as “generative constructors” since they purely generate an instance.

// main() {
// var obj3 = new class3();
// obj3.fun3();
// }
// class class3 {
// class3() {
// print("Hello");
// }
// fun3() {
// print("I am Vishal");
// }
// }

/// Parameterized Constructor
// main() {
// var obj4 = new class4("Amit");
// obj4.fun4();
// }
// class class4 {
// var name; //OR var _name;
// ///1st way
// class4(name) {
// this.name = name; //OR _name = name;
// }
// ///2nd Way (Short Version of Parameterized Constructor)
// //class4(this.name);
//
// // "this" keyword is used to indicate that passing the value of parameter "name" into the class Variable "name" and
// // calling the class Variable "name" in the function fun4().The "this" keyword refers to the current instance.
// // Use this only when there is a name conflict
// // The this keyword is used to refer the current class object.
// // It indicates the current instance of the class, methods, or constructor.
// // It can be also used to call the current class methods or constructors.
// // It eliminates the uncertainty between class attributes and the parameter names are the same.
// //"this" keyword can be used to call instance variable of current class.
// //"this" can be used to set the values of the instance variable.
// //"this" can be used to return the current class instance.
//
// fun4() {
// print("I am " + name); //OR print("I am" + _name);
// }
// }

/// Named Constructor
/// Implementation
// class_name.constructor_name ( parameters ){
// // Body of Constructor
// }

// main() {
// //we can keep desired Constructor name in Named Constructor
// //Default Constructor and Parameterized Constructor can't be used Simultaneously
// var obj5 = class5.myConstructor("Vishal"); //Object making using Parameterized Constructor
// obj5.fun5();
// }
// class class5 {
// var name;
// class5.myConstructor(name) {
// //print("hello");
// this.name = name;
// }
// fun5() {
// print("My Name is " + name);
// }
// }
main() {
class6 obj = new class6.myConstructor1("Yogesh", 40);
class6.myConstructor2(5,5);
class6.myConstructor3();
obj.fun6("Ramesh");
}
class class6 {
class6.myConstructor1(String s, int i) {
print("hello");
print("My Father's name is " + s + " and his age is ${i}" );
}
class6.myConstructor2(int a, int b) {
print("Sum of a and b is : ${a + b}");
}
class6.myConstructor3() {
print("Default Constructor");
}
fun6(String r) {
print("My Name is ${r}, " + r);
}
}

// main() {
// demo obj = new demo();
// obj.demo1(3);
// }
// class demo {
// demo() {
// print("One");
// }
// demo1(int i) {
// print("Two");
// }
// }

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter