Question: In some way I'm trying to avoid multiple reference to an specific object. I have the following:

```
public class A
{
   private C c;

   public A()
   {
      this.c = new C();
   }

   public C getC()
   {
       return this.c;
   }
}

```

Then I have:

```
public class B extends A
{
   private C c;

   public B()
   {
       super();
   }

   public void someMethod()
   {
       // I want to avoid this
       this.c = getC();

       // But I want to allow the execution of methods inside C
       getC().someMethodOfC();
   }
}

```

I guess that in C++ it could be done with some operator overloading but I've seen that in Java this is not possible.

Is there any way to only have one reference of the object in Java (And don't allow the creation of more references)

Answer: 
Here is the solution to your problem. Note that I have to check if `i` is odd, due to Python indexes starting from 0. For example, in Python, an index of 1 is the second position.

```
num = input("Enter a number: ")

return_num = ""
# Iterates through input
for i in range(len(num)):
    # Checks if digit is at even position
    if i % 2 == 1:
        # If so, adds it to return_num
        return_num += num[i] # + " " if you want spaces between numbers

print(return_num) # Prints 4690 with your input

```

Alternatively, you could achieve this using one for-loop. (Credit to OneCricketeer.)

```
num = input("Enter a number: ")

return_num = ""
# Iterates through specified indexes of input
for i in range(1, len(num), 2): 
        return_num += num[i] # + " " if you want spaces between numbers

print(return_num) # Prints 4690 with your input

```

Or, if you want to have the shortest program humanly possible to solve your problem (Credit to Tomerikoo):

```
num = input("Enter a number: ")
print(num[1::2]) # Prints 4690 with your input

```
This is one way how you can do it

```
# iterate over string
x = 34567910
string = str(x)
for index in range(len(string)):
    # check if index is divisible by 2
    if index % 2 != 0:
        # print character at index
        print(string[index], end = '')

```