Questions tagged [shadowing]

In computer programming, shadowing occurs when a variable declared within a certain scope (decision block, method or inner class) has the same name as a variable declared in an outer scope. This can lead to confusion, as it may be unclear which variable subsequent uses of the shadowed variable name refer to, which depends on the name resolution rules of the language.

One of the first languages to introduce variable shadowing was ALGOL, which first introduced blocks to establish scopes. It was also permitted by many of the derivative programming languages including C++ and Java.

The C# language breaks this tradition, allowing variable shadowing between an inner and an outer class, and between a method and its containing class, but not between an if-block and its containing method, or between case statements in a switch block.

237 questions
0
votes
1 answer

Overlay div on td one row above hovered td

I have a table that his comprised of 3 columns and n number of rows. What I'm trying to do is this. When you hover over a td all the td's above that will be "shaded" I tried doing this with just a onmouseover and box-shadow but the text would appear…
Drew Landgrave
  • 1,515
  • 3
  • 13
  • 23
-1
votes
1 answer

How to get this json data using Python and put into pandas dataframe?

I am trying to get a JSON data every 1-minute using python and put it into pandas dataframe. The issue is only I am getting the data only the first time and then I am getting errors(Retrying). The code is here: import requests import json import…
-1
votes
1 answer

Shadowing in without "let"

From my understanding, shadowing in Rust allows you to use the same variable by using let and re-declaring the variable e.g. let x = 5; let x = x + 1; let x = x * 2; println!("The value of x is: {}", x); but, if you make the variable mutable,…
0xsegfault
  • 2,899
  • 6
  • 28
  • 58
-1
votes
1 answer

How do you shadow a final variable from a parent class?

I have a parent class in which i have a final static int which i need to shadow in a child class. In the parent class i use a method "print", which i override in my child class. If i use this code, the method print will use the MINIMUMPRIJS from my…
wetallday
  • 31
  • 1
  • 7
-1
votes
3 answers

c# two levels inheritance hiding overriding methods

could you please tell me why the result of the code below is BaseClass::method? I was thinking that DerivedClass2 will just override the virtual method of DerivedClass1 which is declared as new, meaning that the BaseClass method is not used. Or…
Dave ddd
  • 117
  • 9
-1
votes
3 answers

Shadowing variables in methods

I was reading the certification book of Java 6. And there was an example about "Shadowing variables": package scjp; class Class1 { int number = 28; } public class Example { Class1 myClass = new Class1(); void changeNumber( Class1…
CristianC
  • 15
  • 1
  • 6
-2
votes
2 answers

Python TypeError: 'tuple' object is not callable when using list comprehension inside for loop

I'm trying to generate a list of strings using a list comprehension, where the string is formatted using f-strings: features = [("month", (1, 12)), ("day_of_year", (1, 365))] for feature, range in features: cols=…
RicardoC
  • 109
  • 1
  • 2
  • 9
-2
votes
1 answer

What does GCC compiler do to type conversion? Why the output on mac and linux are different?

I did the type conversion of variable b(declaration outside the scope) in a scope and give a new val to b, and when the scope ends, the val of b seem to be wrong. This happens on my macbook, which version of gcc is gcc-8 (Homebrew GCC 8.3.0) 8.3.0. …
-2
votes
1 answer

Shadowing a global function

Is there a way to shadow a function at global scope in a golang package? In some go file, I DONT want users to be able to call BFunc... That is, I want to wrap it... // Lets say this package provides BFunc() // And I have a naughty user who wants…
jayunit100
  • 17,388
  • 22
  • 92
  • 167
-4
votes
2 answers

Can anybody explain me the output of this code?

This is the code I am compiling. var a = 10; var c = 5; b(40); function b(x) { a(20); a=40; c=50; function a() { console.log(x);} } console.log(a); console.log(c); Can you tell me the output and explain it?
-7
votes
1 answer

Explain the questions mentioned in the comments

class Bar{ int barNum=28; } class Foo{ Bar myBar = new Bar(); void changeIt(Bar myBar){ //Here is object's reference is passed or the object is passed? myBar.barNum = 99; …
-7
votes
1 answer

How do I achieve the equivalent of type shadowing by a derived class?

I would like to write something like the following: class A { virtual typedef int foo_t; void bar() { cout << "foo_t is " << get_demangled_name(typeid(foo_t)); } } class B : A { typedef float foo_t; } And for bar() to…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1 2 3
15
16