Computer Applications
How is following statement different from statement given in previous question ?Student stud1 = new Student( );
Java Classes
10 Likes
Answer
The statement Student stud1; only declared a variable stud1 of type Student.
The statement Student stud1 = new Student( ); not only declares a variable but it actually instantiates the object stud1 of class Student by using the 'new' keyword.
Answered By
8 Likes
Related Questions
Why are classes said to be abstractions of or a set of objects ?
Why are objects said to be instances of a class ?
Consider the following code fragment assuming that a class namely Student has been defined earlier :
Student stud1;What is above statement doing ?
Write a program to accept a number and check whether it is a 'Spy Number' or not. (A number is spy if the sum of its digits equals the product of its digits.)
Example: Sample Input: 1124
Sum of the digits = 1 + 1 + 2 + 4 = 8
Product of the digits = 1*1*2*4 = 8