a) How do you declare an object’s reference variable? What does it store? b) When will a class have a default constructor? How do you create a default constructor in Eclipse?
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
a) How do you declare an object’s reference variable? What does it store?
b) When will a class have a default constructor? How do you create a default constructor
in Eclipse?
A) Question Ans:-
Reference variable:
It's not always the case that copies of an object are used when it's assigned to a variable or passed as an argument to a method. Instead, we make use of references to such objects, which simply means that a reference is an address used to denote the location of an object's variables and methods.
Example:
//Class definition
public class Student {
// field or data member or instance variable
int id;
String name;
//Main definition
public static void main(String args[]) {
// creating an object of Student
Student s1;
s1 = new Student();
// accessing member through reference variable
System.out.println(s1.id);
System.out.println(s1.name);
}
}
Step by step
Solved in 3 steps