Found 34488 Articles for Programming

Abstract Classes in C#

karthikeya Boyini
Updated on 19-Jun-2020 07:34:12

2K+ Views

An abstract class in C# includes abstract and non-abstract methods. A class is declared abstract to be an abstract class. You cannot instantiate an abstract class.Let us see an example, wherein we have an abstract class Vehicle and abstract method display()−public abstract class Vehicle {    public abstract void display(); } The abstract class has derived classes: Bus, Car, and  Motorcycle. The following is an implementation of the Bus derived class −public class Bus : Vehicle {    public override void display() {       Console.WriteLine("Bus");    } } ExampleLet us see the complete example of abstract classes in C# −Live ... Read More

A Deque Class in C#

Samual Sam
Updated on 19-Jun-2020 07:35:29

1K+ Views

The Deque class uses a doubly-linked list to implement its collection of elements.  The doubly-linked lists should have two nodes i.e. front and back nodes. This helps in adding elements on the front and back of the Deque.With the Deque class, you have the ability to add and remove elements from both the sides. This is why Deque is said to be a double-ended queue.The Deque class has the following methods in the Queue class −ClearClears the collection of all of its elementsContainsWhether or not an object is in the collectionToArrayUse the ToArray() method to copy all of the elements ... Read More

‘this’ keyword in C#

karthikeya Boyini
Updated on 19-Jun-2020 07:38:18

9K+ Views

The “this” keyword in C# is used to refer to the current instance of the class. It is also used to differentiate between the method parameters and class fields if they both have the same name.Another usage of “this” keyword is to call another constructor from a constructor in the same class.Here, for an example, we are showing a record of Students i.e: id, Name, Age, and Subject. To refer to the fields of the current class, we have used the “this” keyword in C# −public Student(int id, String name, int age, String subject) {    this.id = id;   ... Read More

Can we overload or override a static method in Java?

karthikeya Boyini
Updated on 01-Dec-2023 11:49:35

3K+ Views

If a class has multiple functions by the same name but different parameters, it is known as Method Overloading. If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its superclass parameter must be different in case of overloading, the parameter must be same in case of overriding. Now considering the case of static methods, then static methods have following rules in terms of overloading and ... Read More

Array To Stream in Java

Samual Sam
Updated on 18-Jun-2020 10:53:23

384 Views

With Java 8, Arrays class has a stream() methods to generate a Stream using the passed array as its source.DescriptionThe java.util.Arrays.stream() method returns a sequential Stream with the specified array as its source. −Arrays.stream(array)DeclarationFollowing is the declaration for java.util.Arrays.stream() methodpublic static Stream stream(T[] array)Type ParameterT − This is the type of the array elements.Parameterarray − This is the source array to be used.Return ValueThis method returns a stream for the array.ExampleThe following example shows the usage of java.util.Arrays.stream() method.Live Demoimport java.util.Arrays; public class Tester {    public static void main(String args[]) {       int data[] = { 1, ... Read More

Array Declarations in Java

karthikeya Boyini
Updated on 18-Jun-2020 09:24:40

723 Views

Here is the syntax for declaring an array variable −SyntaxdataType[] arrayRefVar;   // preferred way. or dataType arrayRefVar[];  // works but not preferred way.Note − The style dataType[] arrayRefVar is preferred. The style dataType arrayRefVar[] comes from the C/C++ language and was adopted in Java to accommodate C/C++ programmers.ExampleThe following code snippets are examples of this syntax −double[] myList;   // preferred way. or double myList[];   // works but not preferred way.Creating ArraysYou can create an array by using the new operator with the following syntax −SyntaxarrayRefVar = new dataType[arraySize];The above statement does two things −It creates an array ... Read More

Array Copy in Java

Samual Sam
Updated on 13-Sep-2023 15:09:03

27K+ Views

Array in Java can be copied to another array using the following ways.Using variable assignment. This method has side effects as changes to the element of an array reflects on both the places. To prevent this side effect following are the better ways to copy the array elements.Create a new array of the same length and copy each element.Use the clone method of the array. Clone methods create a new array of the same size.Use System.arraycopy() method.  The arraycopy() can be used to copy a subset of an array.ExampleCreate a java class named Tester.Tester.javaLive Demopublic class Tester {    public ... Read More

Addition and Concatenation in Java

karthikeya Boyini
Updated on 18-Jun-2020 09:33:21

1K+ Views

'+' operator in java can be used to add numbers and concatenate strings. Following rules should be considered.Only numbers as operands then result will be a number.Only strings as operands then result will be a concatenated string.If both numbers and strings as operands, then numbers coming before string will be treated as numbers.If both numbers and strings as operands, then numbers coming after string will be treated as a string.Above rule can be overridden using brackets().ExampleCreate a java class named Tester.Tester.javaLive Demopublic class Tester {    public static void main(String args[]) {             //Scenario 1: ... Read More

How to replace values of a Python dictionary?

George John
Updated on 15-Jun-2020 08:27:55

9K+ Views

You can assign a dictionary value to a variable in Python using the access operator []. For example,Examplemy_dict = {    'foo': 42,    'bar': 12.5 } new_var = my_dict['foo'] print(new_var)OutputThis will give the output −42This syntax can also be used to reassign the value associated with this key. For example,Examplemy_dict  =  {    'foo': 42,    'bar': 12.5 } my_dict['foo']  =  "Hello" print(my_dict['foo'])OutputThis will give the output −Hello

How can I remove the same element in the list by Python

Vikram Chiluka
Updated on 27-Oct-2022 12:12:50

2K+ Views

In this article, we will show you how to remove the same element in the list in python. In simple words removing common elements from both lists. Below are the various methods to accomplish this task − Using remove() function Using List Comprehension Using Set difference operator Using Set difference() function Assume we have taken two lists containing some elements. We will now remove the same or common elements from both lists. Using remove() function Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task − Create a variable to store the inputList_1. ... Read More

Advertisements