Menu
Topics Index
...
`

Print Student Details2278


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Student Details2278
What will be the output of the following program? Assume that we run LittleFlowerSchool class.
package com.mc.details;

import com.mc.Stud1.Student;
import com.mc.Stud2.StudentDetails;

public class LittleFlowerSchool {
    public static void main(String[] args) {
        Student std = new Student();
        System.out.println("Rank is " + std.rank);
        System.out.println("Marks is " + std.marks);
        System.out.println(StudentDetails.address);
    }
}
package com.mc.Stud1;

public class Student {
    public int rank = 10;
    public double marks = 89;
    public static void main(String[] args) {
        System.out.println(new Student().rank);
        System.out.println(new Student().marks);
    }
}
package com.mc.Stud2;

public class StudentDetails {
    public static String address = "Hyderabad, Andhra Pradesh, India";
    public static void main(String[] args) {
        System.out.println(address);
    }
}

A. Rank is 10
Marks is 89.0
10
89.0
Hyderabad, Andhra Pradesh, India
Hyderabad, Andhra Pradesh, India
B. Rank is 10
10
Marks is 89.0
89.0
Hyderabad, Andhra Pradesh, India
Hyderabad, Andhra Pradesh, India
C. Rank is 10
Marks is 89.0
Hyderabad, Andhra Pradesh, India
D. Some other output
E. Compilation Error or Runtime Error
Topic: Java Package

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is C..here we have the Packages concept which is used to group the classes...we can import using the import keyword..and we can create package using package keyword

Execution:

in LittlerFlowerClass we are creating the instance for the Student class and we are accessing the variables of the class rank and marks so it will print 10 and 89.0 next we are accessing the address of the StudentDetails class..so it will print Hyd,AP,India

Posted by Uday Kumar    2015-01-03 04:21:23


c

Posted by Rajeswari PS    2015-01-03 08:29:48


ANS IS C

Here Concept of "PACKAGE" is uesd which is collection of logically simiar classes.

--In LittleFlowerSchool class two packages are imported:
1)Student class of com.mc.stud1
2)StudentDetails class of com.mc.stud2

--Execution starts from LittleFlowerSchool class.Object of class Student is created.Using that object rank of class Student is printed i.e. 10 will get printed.Then Marks of Student class is printed i.e. 89.0 will get printed.

--Static String of StudentDetails class is printed i.e. "Hyderabad, Andhra pradesh ,India"

Posted by Mânïshå Mùlchåndânï    2015-01-03 10:15:23


C is correct ans
here two packages created and imported , and non-static data members are called by an instance (object) and static data member is called simply along with class name without any object .

Posted by Vikash Atri    2015-01-05 14:32:18


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Mânïshå Mùlchåndânï,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Maheshwari Natarajan. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2015-01-06 04:51:29


© meritcampus 2019

All Rights Reserved.

Open In App