Constructor chaining and inheritance in TypeScript

Typescript constructor and inheritance


Before going to understand the constructor chaining we first, need to know what exactly the typescript constructor is.

Constructor chaining


In typescript constructor is defined with keyword "constructor". The constructor is a special type of function of typescript class and it will be automatically invoked when the first object of the class is created.

Use of typescript constructor

Is to initialize a variable of the class

Typescript constructor Channing: 

Typescript classes support single inheritance the same as other languages.But, here we use the extends keyword to inherit classes in typescript.

See:
  Class employee extends manager
             |                             |
             |                             |
     derive class                base class

Constructor chaining is just a process in which if you have a constructor in your class(derive class), then you need to call base class constructor by your constructor. Here constructor calling is different we are using the super keyword [super(d)].





class manager
{
    duration:number;
    constructor(d:number)
    {
        this.duration=d;
    }
    work():number
    {
        return this.duration;
    }
}
class employee extends manager
{
    empdura :number;
    constructor (du:number,d:number)
    {
        super(d);
        this.empdura=du;
    }
    Mywork():number
    {
        return this.empdura;
    }

}
var emp=new employee(101,69);
console.log(emp.work());
console.log(emp.Mywork());




When to use super keyword in typescript
1.Whenever we need to call the constructor of the base class in case of constructor chaining.

2. In most cases, to access the base class functions, the “super” the keyword is specified inside those functions which have the same name as the base class’s functions have in a derived class.

3. In a derived class, the overridden/hidden functions of a base the class can be accessed/called through a “super” keyword reference because along with a base class constructor the base class functions can also be accessed/refer through “super” keyword.

4. If a constructor is defined only in the derived class, the TypeScript compiler will generate a compile-time error until we use a “super ()” keyword in it.



Reference

Read More

[Updated:2018] Most Popular Sql interview question for freshers

In this tutorial I going to show you some tricky sql interview queries which is ask in fresher's interviews. These query are very simple and easy, I hope it will help you to crack the SQL Server Interview.


Sql interview question for freshers
Sql interview question for freshers



create database DBTest
use DBTest

--Check all information about any database
exec sp_helpdb @dbname='Test11718'

create table Employee
(
 EID int primary key identity(1,1),
 Name varchar(50),
 Age int,
 salary int
)
insert into Employee values('Amar',21,5000),('Carry',22,3000),('Deepak',28,2000),('Ram',21,1000),('XYZ',25,4000)

insert into Employee(Name,Age,Salary) values('Simant',25,500)

Rename a table

sp_rename 'Emp','Employee'

Rename column name

sp_rename 'Employee.salary','EmpSalary'

Add new column

alter table Employee add address varchar(20)

Change the DataType of column

alter table employee alter column address int

Note:

But there is one problem a datatype of column can not be changed when it will have data inside it.
It can be changed also when it will have data too but only in case of upcasting  ex:- int to varchar.

Drop the column

alter table Employee drop column address

--------------------Some Select Command ask in interview-------------------------


  

Get all record of table

select * from Employee

Find Maximum Salary

select MAX(EmpSalary) from Employee

Find Minimum Salary

select MIN(EmpSalary) from Employee

Find Avarage Salary
select AVG(EmpSalary) from Employee

How to find Avarage of string(Like name,address)

select AVG(Name) from Employee

No, you can't find the avarage of name because Operand data type varchar is invalid for avg operator.

Count the record of any column, count function naver count the null value

select count(Name) from Employee

Try MIN and MAX function on another place

select MIN(Name) from Employee
select MAX(Name) from Employee



READ MORE - KNOW MORE


Read More

Stored procedure to insert data into multiple tables in sql server

Inserting into multiple tables:

Introduction: In this article I am going to explain how to insert data into multiple tables . For this you have to basic knowledge of store procedure. Let's get start step by step.

insert data into multiple tables in sql server


Step1:

Create first table: 


create table Registraion
(
regid int primary key identity,
name varchar(50)
)

Step2:

Create second table: 


create table Registraion_Exp
(
regexpid int primary key identity,
regid int foreign key references Registraion(regid),
current_company varchar(50),
current_salary int,
expected_salary int,
notice_period int
)

Step3:

Now, I am creating a store procedure to insert data in two tables at a time in mssql , this is very simple.


Create proc usp_registration_insert
@name varchar(50),
@current_company varchar(50),
@current_salary int,
@expected_salary int,
@notice_period int
as
begin
     insert into Registraion(name)values(@name)
     declare @id int
     select @id = scope_identity()
     insert into Registraion_Exp(regid,current_company,
                        current_salary,expected_salary,
                                    notice_period)                                            values(@id,@current_company,
                      @current_salary,@expected_salary,
                                    @notice_period)         
end



Select @id = scope_identity(): (Use of scope_identity)
Used for selecting the latest value(primary key which is also a foregin key) of table first, if their will no reference between these tables it means that we can not get latest value of first table.


Read More - Know More







Read More

Javascript interview questions and answers for freshers and experienced

                                 What is JavaScript?

JavaScript is a loosely-type client side scripting language that execute in the user's browser.JavaScript interact with html elements in order to make interactive web user interface.JavaScript can be used in various activities like data validation,display popup message.

Javascript interview questions and answers
Javascript interview questions and answers
                                   


Q.1 Can you access Cookie using javascript?
 Yes

Q.2 Can you assign a anonymous function to a variable?
 Yes,But Anonymous JavaScript function assigned to a variable can be called at a later time.

Q.3 Define unescape() and escape() functions?
 See this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape

Q.4 Is a javascript script faster than an ASP script?
 Yes, javascript is faster than ASP script.Because javascript is develop for client side whereas ASP  Script is server side.

Q.5 Can you pass a anonymous function as an argument to another function?
 See this:https://www.dashingd3js.com/lessons/javascript-callback-functions

                                     Javascript tricky interview questions

Q.6 Does JavaScript support automatic type conversion?
 Yes! Javascript support automatic type conversion.

Q.7 Explain the difference between “==” and “===”?
 See this:https://www.c-sharpcorner.com/blogs/difference-between-and-with-example-in-javascript2

Q.8 How to read and write a file using javascript?
 By using java script functions – fopen(),fread() and fwrite().

Q.9 How to delete a Cookie using JavaScript?
 See this: https://stackoverflow.com/questions/10593013/delete-cookie-by-name

Q.10 How to print a web page using javascript?
 window.print();

                                       Javascript tricky interview questions

Q.11 How to read elements of an array in JavaScript?
 var fruit = ["Mango", "Apple", "Banana"];
 var arry_name=["Item1","Item2","Item3"]

Q.12 How to redirect a url using JavaScript?
 window.location = "http://www.abc.com";

Q.13 What are JavaScript Data Types?
 See this: https://www.w3schools.com/js/js_datatypes.asp

Q.14 What is the use of blur function?
  If we use the blur method for the active element, then it loses the active state.

Q.15 What is the purpose of ‘this’ operator in JavaScript?
 When a function is called as a property on a parent object, this refers to the parent object inside that function.

                                         Javascript tricky interview questions

Q.16 Explain what is pop()method in JavaScript?
 See this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop

Q.17 How generic objects can be created?
 See this: https://blog.learntoprogram.tv/javascript-generic-object/

Q.18 What are Screen objects?
 See this: https://www.javatpoint.com/javascript-screen

Q.19 What are the different types of errors in JavaScript?
 See this: https://www.tutorialspoint.com/javascript/javascript_error_handling.htm

Q.20 What are the advantages of using JavaScript?

1.Easy to learn.
2.It execute on client's browser,so eliminate server side processing.
3.It execute on any OS.
4.JavaScript can be used with any type of web page e.g. PHP,ASP.NET,Perl etc.
5.Performance of web page increases due to client side execution.
Read More

Angularjs tricky interview questions

1.What is AngularJS ?

AngularJS is a javascript open source framework used for making extensible web applications and dynamic web pages.It allows you to use HTML as your template language and runs on plain javascript and HTML.

Angularjs tricky interview questions


2.Define scope in AngularJS.

Scope is an object that refers to the application model. It acts as glue between controller and view. Scopes are hierarchical in nature and follow the DOM (Document Object Model) structure of your angular app.

AngularJS has two scope objects: $rootScope and $scope.

$scope
A $scope is a JavaScript object which is used for communication between controller and view. Basically, $scope binds a view (DOM element) to the view model and functions defined in a controller.

$rootScope
The $rootScope is the top-most scope. An app can have only one $rootScope which will be shared among all the components of an app. Hence it acts like a global variable. All other $scopes are children of the $rootScope.

3.Is AngularJS compatible with all browsers? 

Yes.

4.What are directives? 

Directive is used to provide extra functionality on the HTML element. For instance, the ng-click directive gives an element the ability to listen for the click event and run an Angular expression when it receives the event.Directives are what makes the Angular framework so powerful, and, as we’ve seen, we can also create them.
A directive is defined using the .directive() method, one of the many methods available on our applications Angular module.

5.What are the types of Directive?

Element directives
Attribute directives
CSS class directives
Comment directives

6.Explain what are the key features of AngularJS?

Key features of AngularJS are

Scope
Controller
View
Model
Services
Data Binding
Directives
Testable
Filters

7.What is services in AngularJS?

In angularjs service is the function which is used to handle the server communication over the browser with help of XMLHttpRequest object and $http.

8.What is the Template in AngularJS?

The template is the HTML portion of the angular app. It is exactly like a static HTML page, except that templates contain additional syntax which allows data to be injected in it in order to provide a customized user experience.

9.What are basic steps to set up an Angular app?

Create an angular.module
Assign a controller to the module
Link your module to HTML with ng-app
Link the controller to HTML with ng-controller directive.

10.Is AngularJS a library or framework?

AngularJS is not a library but open source client side MVC (Model View Controller) framework for creating dynamic web applications. It is lightweight and can use jQuery library if it's present in your application when the app is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.

11.What is Single Page Application (SPA)? 

SPA is the concept whereby pages are loaded from the server not by doing post backs, rather by creating a single shell page or master page and loading the web pages into the master page.

12.Who created Angular JS?

Angular JS was developed by Misko Hevery and Adam Abrons and later developed by Google.

13.what is the difference between AngularJS and backbone.js?

AngularJS combines the functionalities of most of the 3rd party libraries, it supports individual functionalities required to develop HTML5 Apps.  While Backbone.js do their jobs individually.

14.What is DI (Dependency Injection) and how an object or function can get a hold of its dependencies?

DI or Dependency Injection is a software design pattern that deals with how code gets hold of its dependencies. In order to retrieve elements of the application, the operation “config” uses dependency injection which is required to be configured when the module gets loaded.

The ways that object use to hold of its dependencies are:
Typically, dependency can be created using the new operator.
Dependency can be looked up, by referring to a global variable.
Dependency can be passed to where it is required.

15. What are the major browsers Supported by Angular js?

Here are some major browsers supported by Angular js like:

Mozilla Firefox
Google Chrome
Microsft Edge
IE 10,11
IE Mobile,
Safari, iOS
Android: Nougat (7.0) Marshmallow (6.0)

Read More

Private constructor in c#


Private constructor in c# is a special type of function which name same as the class name. If any class having private constructor it means that we can't create the object of that class. Over you if you want to create the object of class which have private constructor then you have to take a default constructor in your class.

Private constructor in c# is a special type of function which name same as the class name. If any class having private constructor it means that we can't create the object of that class. Over you if you want to create the object of class which have private constructor then you have to take a default constructor in your class

(see the real time example of private constructor).

  public class Program
    {
        private Program(int a, int b)
        {
            a = 10;
            b = 11;
        }
        public Program()
        {
       
        }
    }
    class testing
    {
        static void Main(string[] args)
        {
            Program p = new Program();

        }

    }



Classes Which Loads Only one Time In memory. In Singleton Class Constructor Is Always Private and Object Is Always Static.

Imp. Point:

1.In Singleton Class We Have Only One Object Of A Class.
2.Singleton Class Uses Static so it’s Behavior Is Static.

namespace WindowsFormsApplication3
{

    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Class1 ob = Class1.Create();
            Class1 ob1=Class1.Create();
            Class1 ob2=Class1.Create();
        }
    }

    public class Class1
    {
        Class1()
        {
        }
        static Class1 ob;

        public static Class1 Create()
        {
            if (ob == null)
            {
                ob = new Class1();
                return ob;
            }
            else
           {
            return ob;
            }
        }
    }
}

Can constructor be private
                                         -Yes

Can a Private Constructor have Parameters ?   
                                                                      -Yes.



Must Read :





Read More